Gone Sail wrote: > i wanted to to be generic. Then you may want to look at has_many_polymorphs... (I've always found the minimalist HABTM to be insufficient - people always want to know who related something, and when, so my join tables are always full models of their own)
If A is related to B, and A is related to C, and X is the thing you want to relate to an A-B relationship, or an A-C relationship, then perhaps something like this: A has_many ABjoins has_many Bs through ABjoins has_many ACjoins has_many Cs through ACjoins B has_many ABjoins has_many As through ABjoins AB belongs_to A belongs_to B has_many Xlinks as xlinkable has_many Xs, through Xlinks C has_many ACjoins has_many As through ACjoins AC belongs_to A belongs_to C has_many Xlinks as xlinkable has_many Xs, through Xlinks X has_many Xlinks has_many ABjoins through Xlinks, source ABjoin, Xlinks.xlinkable_type = ABjoin has_many ACjoins through Xlinks, source ACjoin, Xlinkx.xlinkable_type = ACjoin Xlink belongs_to X belongs_to xlinkable, polymorhpic => true belongs_to ABjoin, class_name ABjoin, foreign_key xlinkable_id belongs_to ACjoin, class_name ACjoin, foreign_key xlinkable_id -- Posted via http://www.ruby-forum.com/. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

