简体   繁体   中英

rails 4 has_many :through default order

I have a project model that has many tasks, through a join model. The order of the tasks are stored on the project_tasks model.

How do I do the equivalent of the below in rails 4?

has_many :project_tasks
has_many :tasks, :through => :project_tasks, :order => 'project_tasks.position'
has_many :project_tasks, -> { order(:position) }
has_many :tasks, through: :project_tasks

I hope this helps now in rails 4 and 5 you have scopes for that sort of thing. PS: Keep in mind now when you call project_tasks it will call this scope if you dont want that make scope on model project_tasks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM