I have a many to many relationship between Pumps and Parts. I am storing the Part ids in the Pump document. I would also like to store how many Parts are used in a particular Pump.
Here's what I have, in short
class Pump
include MongoMapper::Document
key :number, String
key :desc, String
key :part_ids, Array
many :parts, :in => :part_ids
end
class Part
include MongoMapper::Document
attr_accessor :pump_ids
key :qty, Integer
key :number, String
key :desc, String
def pumps
Pump.all(:part_ids => self.id)
end
end
Which worked fine until I realized the number of Parts used per Pump is different, So now I need store the qty per the relationship, and maybe some other relational specific info like notes.
Instead of just storing and Array of ids I'd like something like this instead.
[{:pump_id => "12hj3hjkbrw", :qty = 4},
{:pump_id => "ggtyh5ehjrw", :qty = 10, :notes => "when using this part with this Pump please note this"}]
I am not sure how to make this work.