-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
basically, if you want to use a belongs_to association with the same name as the embedded association's class, things break
so, if a company has many customers, and each customer has a company where she works, then I can't embed the association with the correct names...
require 'mongoid' require 'pp' ENV['RACK_ENV'] = 'development' Mongoid.load!("mongoid.yml") class Company include Mongoid::Document field :name, type: String embeds_many :customers end class Customer include Mongoid::Document embedded_in :vendor, class_name: 'Company', inverse_of: :customers belongs_to :company, inverse_of: nil end Company.all.delete a = Company.create! name: 'A' b = Company.create! name: 'B' a.customers.create! company: b customer = a.reload.customers.first pp customer.vendor # => nil **(expecting `a`)** pp customer.company # => `a` **(expecting `b`)**