So I’m trying to do a find with an order by specific column values
thing, but some of the columns are attributes through associations.
So I did some eager loading with the :include option to try and access
the attributes of the object I’m doing the find on. Stuff has been
blowing up on me so far.
Here’s the code in the controller right now:
sort_by = params[:sort_by] || ‘id’
direction = params[:direction] || ‘desc’
@state_agency_grants = Grant.paginate(:all, :include =>
[:funding_entity, :creator_entity, applying_entity], :order=>
“#{sort_by} #{direction}” ,:page => params[:page], :per_page => 50)
So yea, passing what to sort by as a parameter, etc
etc. :funding_entity is of type FundingEntity while :creator_entity
and :appying_entity are of AccountEntity.
Some of the params[:sort_by] I’ve passed are:
funding_entity.name => The multi-part identifier “funding_entity.name”
could not be bound.
funding_entity => Invalid column name ‘funding_entity’.
Okay, its checking the database and not the model.
Well, funding_entities is a table… maybe that will work?
funding_entities.name => Incorrect syntax near ‘.’.: SELECT * FROM
(SELECT TOP 5 * FROM (SELECT TOP 5 [grants].[id] AS t0_r0, [grants].
[created_by] AS t0_r1, … (40 more of these) … ORDER BY
funding_entities.name asc) AS tmp1 ORDER BY funding_entities.[name]
DESC) AS tmp2 ORDER BY funding_entities.[name] asc
Not sure why this happens. Its trying to do funding_entities.[name]
or something with escape characters?
I could sort by funding_entity_id, but that’s not very useful to the
end user. I feel like I’m doing it as described here:
Any help would be great.
Thanks,
Brian B.