활성 레코드와 직접 관계를 통해 has_many를 필터링하는 가장 좋은 방법을 찾는 데 어려움이 있습니다. 나는이 문제를 거의 다룰 수있는 많은 게시물을 찾았지만 아무 대답도 나에게 도움이되지 못했다.연관을 통해 has_many의 필드 필터링
그룹 :
has_many :taggings, as: :taggable
has_many :tags, :through => :taggings
사용자 :
has_many :taggings, as: :taggable
has_many :tags, :through => :taggings
나는 하나의 그룹 태그를
이 다음과 같은 방식의 작품을 일치 태그가 모든 사용자를 찾으려하지만 난 오히려 조립 것 쿼리를 포함한리스트
def interest_matches
matched_users = Array.new
self.tags.uniq.each do |tag|
tag.users.map{ |u| matched_users.push(u) unless matched_users.include?(u) }
end
matched_users
end
많은 조언을드립니다.
갈 :)를 제공합니다. . 감사! – errata
문제 없습니까? 작동합니까? –