On Tue, 13 Apr 2010 10:15:28 +0200 "Sergio Cambra .:: entreCables S.L. ::." <[email protected]> wrote:
> 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 > I will test this later. Thank you! -- 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.
