ruby on rails - ActiveRecord query ordering -


suppose have following models:

class car < activerecord::base   belongs_to :seat   ... end  class seat < activerecord::base   belongs_to :color   ... end   class color < activerecord::base   attr_reader :name   ... end 

if have list of cars, , want order cars color.name, how write order query?

class car < activerecord::base    belongs_to :seat    ...    def cars_order_by_color(car_ids)        where(:id=>car_ids).order(?????) #how order color.name    end      end 

if use joins on query, can sort joined tables (either seats or colors):

car.joins(:seat => :color).order("colors.name") 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -