To change the acquisition method of child model data with desc or asc, you can use the following method.
scope :order_asc, -> { includes(:messages).order('messages.created_at ASC') }
Ruby On Rails: Order by child attribute
Recommended Posts