내 레일 앱에는 많은 사용자가있는 기관 수준의 계정이 있습니다.ActsAsTaggableOn : has_many 관계에있는 자식 개체의 모든 태그 얻기
각 기관마다 많은 프로젝트가 있습니다.
프로젝트는 acts_as_taggable이고 기관의 사용자는 기관의 프로젝트에 태그를 추가 할 수 있습니다.
특정 기관에 속한 프로젝트의 모든 태그 목록을 쿼리하고 싶습니다.
예를 들면, (존재하지 않는) Project.where(institution_id: 1).tags
같은
내가 이것을 촉진 할 수있는 태그의 소유자로 프로젝트의 기관을 설정하고 소유자가 쿼리해야합니까?
class Institution < ActiveRecord::Base
acts_as_tagger
end
class Project < ActiveRecord::Base
acts_as_taggable
end
그런 설정 태그 :
@current_user.institution.tag(@some_project, with: 'tag1, tag2')
... 그리고 태그 점점 :
@current_user.institution.owned_tags
또는 소유권을 설정 필요로하지 않는 방법이있다? (내 데이터에 있지만, 작동) 일부 조정이 필요할 수 있습니다 그 구문은
ActsAsTaggableOn::Tag.
joins(:taggings).
where(taggings: {taggable: current_institution.projects})
:
당신은 이것을 분류하는 것을 끝내 었습니까? – jvillian