0

这种关联在 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        
4

1 回答 1

0

尝试这个:

class User < ActiveRecord::Base
  has_many :user_quests,
           -> { includes(:quest).order('quests.status DESC') },
           :dependent => :delete_all
end
于 2013-09-12T23:01:39.517 回答