Rails order by in associated model

后端 未结 5 1430
醉酒成梦
醉酒成梦 2020-12-14 06:01

I have two models in a has_many relationship such that Log has_many Items. Rails then nicely sets up things like: some_log.items which returns all of the associ

5条回答
  •  暖寄归人
    2020-12-14 06:36

    set default_scope in your model class

    class Item < ActiveRecord::Base
      default_scope :order => "some_col DESC"
    end
    

    This will work

提交回复
热议问题