这种关联在Rails 3中运行正常,因此对于用户,我可以通过Quest.status订购UserQuest。我无法在Rails 4中找到如何获得这个。感谢您的帮助。
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
答案 0 :(得分:0)
试试这个:
class User < ActiveRecord::Base
has_many :user_quests,
-> { includes(:quest).order('quests.status DESC') },
:dependent => :delete_all
end