ActiveAdmin: sort by child association's property

前端 未结 4 1439
太阳男子
太阳男子 2021-02-13 17:08

I am having these objects:

class District < ActiveRecord::Base
  belongs_to :city
end
class City < ActiveRecord::Base
  has_many :districts
end
         


        
4条回答
  •  春和景丽
    2021-02-13 17:34

    Use the name of the table, probably cities. It might look like this:

    District.joins(:city).order("cities.name")
    

提交回复
热议问题