このようなグループクラスがあります。グループには多くの人がいます。
class Group < ActiveRecord::Base
has_many :people
def notices
Notice.where(:person_id => people).where("radius <= ?", radius)
end
end
私の通知コントローラーでは、すべてのユーザー グループからのすべての通知を重複なく表示したいと考えています。現在、私はこれを行っていますが、これは不自由です。各グループからのクエリを組み合わせて、配列ではなくリレーションを返す方法はありますか?
class NoticesController < ApplicationController
def index
@groups = current_person.groups
@notices = []
@groups.each do |g|
@notices += g.notices
end
end
end
ありがとう