Thursday, 12 September 2013

Retrieve child records ordered by another parent

Retrieve child records ordered by another parent

This associations worked OK in Rails 3, so for a User I could get
UserQuest ordered by Quest.status. I can't find how to get this in Rails
4. Thanks for the help.
class Quest < ActiveRecord::Base
has_many :user_quests
end
class UserQuest < ActiveRecord::Base
belongs_to :user
belongs_to :quest
end
class User < ActiveRecord::Base
has_many :user_quests, :include => :quest, :order => "Quest.status
DESC", :dependent => :delete_all
end

No comments:

Post a Comment