Right. You'll need to create a new Pairing for each food. ActiveRecord doesn't understand comma-separated ids. e.g.:

Pairing.create(:wine_id => 1, :food_id => 1, :sauce_id => 1)
Pairing.create(:wine_id => 1, :food_id => 2, :sauce_id => 1)
Pairing.create(:wine_id => 1, :food_id => 3, :sauce_id => 1)

Now, this may not exactly fit the relationship you are trying to model. There's also the possibility that what you want is something like this (in rough ASCII art)

Food <------> Wine
  ^                   ^
  v                     |
Sauce <----------|


In that case, you'd have three join models, one between each. However, I was suggesting you might be able to collapse that into the model above, and just not use all of the keys on every record. In that way, you could do something like @wine.foods.map(&:sauces), which would not necessarily be the same collection as @wine.sauces.

Sean

[EMAIL PROTECTED] wrote:
On Sat, 2008-08-16 at 09:56 -0400, Sean Cribbs wrote:
create_table :pairings do |t|
  t.integer :food_id
  t.integer :wine_id
  t.integer :sauce_id
end

Thanks again for your help, Sean, but I am now having a slightly
different problem. The relationship works, but now I cannot get the
table to hold an array for any of the id fields.When I create a pairing,
"Pairing.create :wine_id => '1', :food_id => '1,2,3', :sauce_id => '1'"
only the first id is added to the table. So the second and third value
for the food_id aren't stored in the db. Any thoughts?


Thanks,

Nate

_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant


_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to