Rails order by in associated model

后端 未结 5 1435
醉酒成梦
醉酒成梦 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

    Either of these should work:

    Item.all(:conditions => {:log_id => some_log.id}, :order => "some_col DESC")
    some_log.items.all(:order => "some_col DESC")
    

提交回复
热议问题