매우 이상한 문제가 있습니다.NoMethodError : 클래스 private 메서드`exist_check '가 호출되었습니다.
시나리오 : 나는 각 사진이 앨범에 속하는 MongoDB (mongoid gem)로 Rails에서 사진 모음을 작업 중입니다. 일부 몽고 필드는 우려로 제공되며 모델은 올바르게 네임 스페이스를 사용합니다. 그래서,
우려 : MediaConcerns::Base
module MediaConcerns
module Base
extend ActiveSupport::Concern
included do
field :photo_description, type: String
end
end
end
우려 : MediaCollectionConcerns::Base
module MediaCollectionConcerns
module Base
extend ActiveSupport::Concern
included do
field :album_title, type: String
field :album_description, type: String
end
end
end
그리고 MediaType::Photo
은 다음과 같습니다이다
module MediaType
class Photo
include Mongoid::Document
include Mongoid::Timestamps::Short
include MediaConcerns::Base
embedded_in :photo_album, class_name: 'MediaCollection::PhotoAlbum'
end
end
MediaCollection::PhotoAlbum
동안 :
module MediaCollection
class PhotoAlbum
include Mongoid::Document
include Mongoid::Timestamps::Short
include MediaCollectionConcerns::Base
embeds_many :photos, class_name: 'MediaType::Photo'
end
end
우려와 상관없이이 문제는 지속되며 embedded_in
및 embeds_many
과 관련됩니다. 내가 MediaCollection::PhotoAlbum.new
을하려고 할 때 레일 콘솔
, 그것은 제공 : MediaType::Photo.new
에 대한
NoMethodError: private method `existence_check' called for MediaCollection::PhotoAlbum:Class
from /home/marco/.rvm/gems/ruby-2.4.0/gems/mongoid-6.1.0/lib/mongoid/relations/macros.rb:355:in `relate'
from /home/marco/.rvm/gems/ruby-2.4.0/gems/mongoid-6.1.0/lib/mongoid/relations/macros.rb:85:in `embeds_many'
from /home/marco/workspace/backend/app/models/media_collection/photo_album.rb:10:in `<class:PhotoAlbum>'
from /home/marco/workspace/backend/app/models/media_collection/photo_album.rb:2:in `<module:MediaCollection>'
from /home/marco/workspace/backend/app/models/media_collection/photo_album.rb:1:in `<top (required)>'
그리고 같은 :
NoMethodError: private method `existence_check' called for MediaType::Photo:Class
from /home/marco/.rvm/gems/ruby-2.4.0/gems/mongoid-6.1.0/lib/mongoid/relations/macros.rb:355:in `relate'
from /home/marco/.rvm/gems/ruby-2.4.0/gems/mongoid-6.1.0/lib/mongoid/relations/macros.rb:56:in `embedded_in'
from /home/marco/workspace/backend/app/models/media_type/photo.rb:15:in `<class:Photo>'
from /home/marco/workspace/backend/app/models/media_type/photo.rb:2:in `<module:MediaType>'
from /home/marco/workspace/backend/app/models/media_type/photo.rb:1:in `<top (required)>'
문제는 무엇입니까? 관계 (embeds_many
및 embedded_in
)를 제거 (디버그 전용)하면 문제가 해결되지만 해당 문서를 임베드해야합니다!
아마 레일은 :photos
찾을 수없는,하지만 난 class_name: 'MediaType::Photo'
로 mongoid 문서는 제안, 같은 내가 도움이 필요 'MediaCollection::PhotoAlbum'
지정되어 지정했습니다. 감사.