I have 3 models, let''s call them Recipe, Fruit and Nut, and I need a
DRY way to set up their relationships.
Fruits and Nuts have different sets of properties
Fruits and Nuts go into a Recipe
A join model would be useful to track how much Fruit or Nut goes into a
Recipe
Different Recipes may use a Nut with the name, but different property
values
I might want to add a Twig or Llama model to my Recipes
Right now I have a separate join models that do pretty much the same
for each of Fruit and Nut, but it''s getting really wet (opposite of
DRY). It works just fine, but the code is getting really redundant.
Untill I can hack rails so has_many :through works with polymorphic
associations, what is a good way to do this?
class Recipe < AR::B
has_many :fruitadditions
has_many :fruits, :through => :fruitaddition
has_many :nutadditions
has_many :nuts, :through => :nutaddition
end
class Fruit < AR::B
has_many :fruitadditions
has_many :recipes, :through => :fruitadditions
end
class Nut < AR::B
has_many :nutadditions
has_many :recipes, :through => :nutadditions
end
TIA
--Dean
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---