evan / has_many_polymorphs

An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/
Academic Free License v3.0
201 stars 57 forks source link

Using :parent_extend #13

Open ghost opened 14 years ago

ghost commented 14 years ago

I was hoping somebody might point me in the right direction. I have a class Ad that has a number of different placements on a website. It has_many_polymorphs :placements, :from => [:categories, :products, :pages, :menu_items], giving me the ability to have an ad show up on a number of different models - all of this works great!

I'd like to use two more attributes on each ad - one is position for acts_as_list, and the other is location which would just be a string. I have set up the placements table with these two new fields, but I can't figure out how to extend the Ad class to include these join attributes so I can refer to these attributes when I call for child_class.ads.first.position for instance. I think I'm supposed to be using :parent_extend to assign the joined attrs to the Ad model when a child references it. Any help?