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

前端 未结 8 1275
北恋
北恋 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:10

    has_many :users, -> { order(:last_name, :first_name) }, :through => :assignments, source: 'user'

提交回复
热议问题