하나의 부모로부터 동일한 자식에 대해 여러 개의 다형성 관계 (has_many_polymorphs plugin
)를 정의하려고합니다.하나의 모델에 여러 개의 has_many_polymorphs가 있습니다.
참고 많은 시청자가
참고 많은 편집자가 어느 사용자 또는 그룹이 될 수
시청자
권한이 note_id
, viewer_id
, viewer_type
, editor_id
, editor_type
필드 협회의 모델 중 하나를 사용자 또는 그룹이 될 수
편집자 한 내가 참고 모델에 정의 된 하나 개의 has_many_polymorphs 관계를 가지고 예상대로
모든 밖으로 작동
이제 문제는 내가 두 번째 관계
class Note < ActiveRecord::Base
has_many_polymorphs :viewers, :through => :permissions, :from => [:users, :groups]
has_many_polymorphs :editors, :through => :permissions, :from => [:users, :groups]
end
class Permission < ActiveRecord::Base
belongs_to :note
belongs_to :viewer, :polymorphic => true
belongs_to :editor, :polymorphic => true
end
Note.first.viewers << User.first # => [#<User id: ....>]
# >>>>>>>>
Note.first.editors << User.first
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.constantize
... vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/base.rb:18:in `instantiate'
내가 has_many_polymorphs
의 정의를 정제 시도했지만 작동하지 않았다을 추가 할 때 나타나기 시작. ViewPermission < Permission
및 EditPermission < Permission
의 STI 모델조차도 아닙니다.
모든 생각/문제 해결 방법/문제 포인터는 높이 평가됩니다.
레일 2.3.0
난 당신이 –