Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:inverse_of association option not working with eager_loading. #30402

Closed
kuzukuzu opened this issue Aug 25, 2017 · 1 comment
Closed

:inverse_of association option not working with eager_loading. #30402

kuzukuzu opened this issue Aug 25, 2017 · 1 comment

Comments

@kuzukuzu
Copy link
Contributor

:inverse_of association option not working with eager_loading.

Steps to reproduce

class User < ActiveRecord::Base
  has_many :posts, inverse_of: :user
end

class Post < ActiveRecord::Base
  belongs_to :user, inverse_of: :posts
  belongs_to :category
end

user = User.first

puts "without eager_loading:"
puts user.object_id == user.posts.first.user.object_id
puts ""

puts "with eager_loading:"
puts user.object_id == user.posts.eager_load(:category).first.user.object_id

Expected behavior

Expected outputs are as below.

without eager_loading:
true

with eager_loading:
true

Actual behavior

Actually like this.

without eager_loading:
true

with eager_loading:
false

Further note

In my survey, it derives from changes in 5.1 release.

2017-08-25 15 05 32

The block passed to super method isn't executed with eager_loading.

2017-08-25 15 06 37

Is this intended change?

System configuration

Rails version: 5.1.2

Ruby version: 2.3.1

@kamipo kamipo closed this as completed in 1a723c6 Aug 25, 2017
@kamipo
Copy link
Member

kamipo commented Aug 25, 2017

Thanks for the report. This regression was caused by caa178c.
Fixed in 1a723c6.

kamipo added a commit that referenced this issue Aug 29, 2017
This regression was caused by caa178c. The block for
`set_inverse_instance` should also be passed to join dependency.

Fixes #30402.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants