Created
May 4, 2012 19:43
-
-
Save jingoro/2597258 to your computer and use it in GitHub Desktop.
Mongoid Ambigious Relation Bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
require 'mongoid' | |
Mongoid.configure do |config| | |
config.master = Mongo::Connection.new.db("mongoid-test") | |
end | |
class Group | |
include Mongoid::Document | |
has_many :employees, class_name: 'Person', foreign_key: :employer_id | |
has_many :subcontractors, class_name: 'Person', foreign_key: :client_id | |
end | |
class Person | |
include Mongoid::Document | |
belongs_to :employer, class_name: 'Group' | |
belongs_to :client, class_name: 'Group' #, inverse_of: :subcontractors | |
end | |
a = Group.create! | |
b = Group.create! | |
person = Person.new(employer: a, client: b) | |
p person.employer == person.client # should be false | |
person.save! | |
person.reload | |
# this shows false on mongoid 2.4.8, true on mongoid 2.4.9 | |
p person.employer == person.client # should be false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment