Skip to content

Instantly share code, notes, and snippets.

@greyblake
Created September 26, 2011 09:13
Show Gist options
  • Save greyblake/1241912 to your computer and use it in GitHub Desktop.
Save greyblake/1241912 to your computer and use it in GitHub Desktop.
Misunderstanding of :inverse_of?
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