Thanks Sergio, it works like a charm!

On Nov 3, 9:58 am, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Miércoles, 3 de Noviembre de 2010 09:28:50 Pedro G. escribió:
>
>
>
>
>
> > Hi,
>
> > I've defined a polymorpic associations between my modes in the
> > following way:
>
> > class User < ActiveRecord::Base
> >   has_many :items, :as => :agent
>
> > class Item < ActiveRecord::Base
> >   belongs_to :agent, :polymorphic => true
>
> > Agents can be users or clubs
>
> > In the items controller I want to sort the agent column according to
> > the name and surname of the agent (I know in advance that in this
> > controller I will be displaying user agents), so per the API
> > documentation I should do something like:
>
> > config.columns[:agent].sort_by :sql => "concat(name, surname)"
>
> > That of course doesn't work since it is not joining with the
> > corresponding users table. I've tried also:
>
> > config.columns[:agent].includes = [:user]
>
> > But that doesn't work either because it joins with the correct table
> > but it is not able to identify the join column properly (it looks for
> > an user_id instead of agent_id in items table)
>
> > My question is: how can I make the sort_by :sql work with this
> > polymorphic association?
>
> Define joins_for_collection method in the controller and return a string with
> the sql join clause.
>
> --
> 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.

Reply via email to