Created
September 26, 2011 09:13
-
-
Save greyblake/1241912 to your computer and use it in GitHub Desktop.
Misunderstanding of :inverse_of?
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
class User < ActiveRecord::Base | |
has_many :emails, :inverse_of => :user | |
end | |
class Email < ActiveRecord::Base | |
belongs_to :user , :inverse_of => :emails | |
end | |
# spec 1 | |
u = User.find(1) | |
e = u.emails.first | |
# fails in Rails 3.0 and Rails 3.1 | |
# but I expect it to pass! | |
u.object_id.should == e.user.object_id | |
# spec 2 | |
u = User.find(1, :include => :emails) | |
e = u.emails.first | |
# fails in Rails 3.0 but passes in Rails 3.1 | |
u.object_id.should == e.user.object_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment