On Lunes, 12 de Abril de 2010 22:21:45 Klaus escribió: > Hello, > > I have some trouble searching through a polymorphic association. > On normal has_many associations I do it like it's told in api-column > documentation: CONCAT(..., ' ', ...) works very well! > > BUT: Is there an easy way to search in polymorphic associations too? > > I'm searching in the table where all the polymorphic stuff ( _type and > _id) is. > How can I include columns from the member tables in this search? > > e.g. > Company: has_many people, :as => :staff > and > Person: belongs_to :staff, :polymorphic => true > > I'd like to search for a person in the people table, and also search > for the name of the company which is in the companies table. > > I hope this is at least a little bit understandable ;)
You can't do a join with a polymorphic association, because when you build the query you don't know what tables you have to join with. You can add a fixed join with company defining joins_for_collection: def joins_for_collection "LEFT JOIN companies ON people.staff_id=companies.id AND people.staff_type = 'Company'" end -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 50.018 Zaragoza T) 902 021 404 F) 976 52 98 07 E) [email protected] -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.
