How do I order a has_many through association in Ruby on Rails?

前端 未结 8 1280
北恋
北恋 2020-12-15 02:45

Given the following AR models, I would like to sort users alphabetically by last name when given a handle to a task:

#user
has_many :assignments
has_many :ta         


        
8条回答
  •  一向
    一向 (楼主)
    2020-12-15 03:16

    The M.G.Palmer's approach works well, however table name is involved. There is a better way to do it:

    has_many :users, :through => :assignments, :order => [ :last_name, :first_name ]
    

提交回复
热议问题