出于摘要邮件的目的,我想获得哪些用户可以看到我的应用程序的答案。
用户应该只看到他已经订阅的所有组中投票最高的 5 个答案。
协会:
Answer
# Returns 5 the most voted answers
#
scope :best, order("votes_count DESC")
belongs_to :user
belongs_to :group
User
belongs_to :group
has_many :answers, :dependent => :destroy
has_many :groups, through: :subscriptions
Group
has_many :subscriptions
has_many :users, through: :subscriptions
has_many :questions
has_many :answers
所以我正在寻找如何做到这一点的最佳方法:
class BestAnswers
def self.for_user(user)
answers = []
user.groups.each |group|
answers << group.answers
end
return answers
end
end