0
我對mongoid完全陌生。在類關係定義中是否有任何選項或某些東西來啓用它?Mongoid:如何引用N對N關係中的父對象屬性
class Band
include Mongoid::Document
field :name, type:String
has_and_belongs_to_many :members
end
class Member
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :bands
end
andy = Member.new(name: 'Andy Bell')
ride = Band.new(name: 'Ride')
ride.members << andy
oasis = Band.new(name: 'Oasis')
oasis.members << andy
andy.bands #=> returns: [] (empty array)
andy.band_ids #=> returns: [BSON::ObjectId('53586a786d6163870c030000'), BSON::ObjectId('53586a786d6163870c040000')]