1
has_and_belongs_to_many가 다른 클래스의 내장 된 모델에서 외래 키와 함께 작동하도록하는 쉬운 방법이 있습니까?Mongoid : 포함 된 문서의 외래 키와 has_many
내 사용 사례는 다음과 같습니다
class Account
include Mongoid::Document
has_and_belongs_to_many :users
end
class User
include Mongoid::Document
embeds_many :memberships
end
class Membership
include Mongoid::Document
belongs_to :account, autosave: true
embedded_in :user
end
아이디어는 회원의 모델은 또한 역할과 회원 관련 데이터를 포함하고 있다는 점이다.
그러나 데이터베이스에 사용자가 임베디드 멤버십의 계정에 대해 여러 개의 외래 키를 가지고 있어도 계정의 has_and_belongs_to_many는 이러한 사용자를 선택하지 않습니다.