Reputation: 3187
I am new to MongoId. I saw the document by using embeds_many and embedded_in. Just wonder do I need to use it as a pair?
class Band
include Mongoid::Document
embeds_many :albums
end
class Album
include Mongoid::Document
field :name, type: String
embedded_in :band
end
Thanks
Upvotes: 0
Views: 42
Reputation: 434945
The fine manual is fairly clear on this:
The parent document of the relation should use the
embeds_many
macro to indicate it has n number of embedded children, where the document that is embedded usesembedded_in
.
[...]Definitions are required on both sides to the relation in order for it to work properly.
So yes, you need both or it won't work properly.
Upvotes: 1