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

Fix preloading on AR::Relation where records are duplicated by a join #36429

Merged
merged 1 commit into from Jun 6, 2019

Conversation

@bogdan
Copy link
Contributor

@bogdan bogdan commented Jun 6, 2019

Problem

Fixes #36396

Solution

Using an unknown Hash#compare_by_identity to allow equal hash keys.
When hash has this feature enabled, cache keys become unique using key1.object_id == key2.object_id not key1 == key2.

❤️ ❤️ ❤️ RUBY ❤️ ❤️ ❤️

https://apidock.com/ruby/Hash/compare_by_identity

cc @kamipo @pstare

@bogdan bogdan force-pushed the fix-preloading-duplicate-records branch from 6ce2286 to 2250c8a Jun 6, 2019
@bogdan bogdan force-pushed the fix-preloading-duplicate-records branch from 2250c8a to 30c1999 Jun 6, 2019
@kamipo
Copy link
Member

@kamipo kamipo commented Jun 6, 2019

Is there no need to change these?

@records_by_owner ||= owners.each_with_object({}) do |owner, result|

@records_by_owner = owners.each_with_object({}) do |owner, result|

@kamipo
Copy link
Member

@kamipo kamipo commented Jun 6, 2019

I've confirmed, unlike (result[owner] ||= []) << record, result[owner] = ... has no side-effect even if owners are duplicated.

result[owner] = Array(owner.association(reflection.name).target)

@kamipo kamipo merged commit e3c1f42 into rails:master Jun 6, 2019
2 checks passed
rafaelfranca added a commit that referenced this issue Jun 6, 2019
Fix preloading on AR::Relation where records are duplicated by a join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants