Overriding Active Query construct in Rails

I have the following trying to pull out a selection of Model instances from my DB with this:

@coasters = Coaster.joins(:park).order('parks.name ASC').order('coasters.name ASC')

Near the end of my index action I need to override the order part of the above query so I do the following:

@coasters = @coasters.except(:joins).reorder('order ASC')

But I get this error:

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "parks" LINE 1: SELECT "coasters".* FROM "coasters" ORDER BY parks.name AS... ^ : SELECT "coasters".* FROM "coasters" ORDER BY parks.name ASC, coasters.name ASC, "order" ASC LIMIT 25 OFFSET 0

Any ideas as to how I can solve it?


You should consider using the lazy load feature and do not perform any order at all, before you are sure on what sorting you need.

@coasters = Coaster.where(...).joins(...)

and then

@coasters = @coasters.order(...)

Need Your Help

How to implement MVC pattern in Polymer 1.0?

polymer polymer-1.0 paper-elements polymer-starter-kit

Can we define controller for polymer element? For example, I have a ListView as element.Now I want to implement onClickEvent() in controller to keep business / other logic separate from View. So is...