Rails: How to sort many-to-many relation

前端 未结 3 649
攒了一身酷
攒了一身酷 2021-01-29 04:10

I have a many-to-many relationship between a model User and Picture. These are linked by a join table called Picturization.

If I obtain a list of users of a single pict

3条回答
  •  伪装坚强ぢ
    2021-01-29 05:04

    Have an additional column something like sequence in picturization table and define sort order as default scope in your Picturization

    default_scope :order => 'sequence ASC'
    

    If you want default sort order based on modified_at then use following default scope

    default_scope :order => 'modified_at DESC'
    

提交回复
热议问题