Sort in Ascending Order Rails

后端 未结 5 1606
我寻月下人不归
我寻月下人不归 2021-02-02 08:46

Hi I have this model

Model item

class Inventory::Item < ActiveRecord::Base
  has_many :types, :class_name => \"ItemType\"
  attr_accessible :na         


        
5条回答
  •  天涯浪人
    2021-02-02 09:30

    Something like this should do the trick...

    ItemType.includes( :item ).order( 'inventory_items.name DESC' )
    

    Also, if you need to do this in many locations, you can accomplish the same thing by providing an :order parameter to your has_many call, instead - http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many.

提交回复
热议问题