-
Notifications
You must be signed in to change notification settings - Fork 536
Fix include_optional_linkage_data with joins #1450
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 include_optional_linkage_data with joins #1450
Conversation
When the user adds a join in `records`, it confuses `get_join_arel_node` because it finds the same number of joins before & after adding a join for `include_optional_linkage_data` (or equivalently for `always_include_*_linkage_data`). This commit falls back to searching the existing arel nodes for a compatible join and uses that if found.
This has had a hugely positive impact on performance for us. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks @pjungwir
Fix include_optional_linkage_data with joins (cerebris#1450)
When the user adds a join in `records`, it confuses `get_join_arel_node` because it finds the same number of joins before & after adding a join for `include_optional_linkage_data` (or equivalently for `always_include_*_linkage_data`). This commit falls back to searching the existing arel nodes for a compatible join and uses that if found.
Hey, thanks for this fix. But I have another problem, more tricky 😬 I have a In has_one :patient_enrolled_journal_event In has_one :patient_enrolled_journal_event,
exclude_links: :default,
foreign_key_on: :related,
relation_name: :patient_enrolled_journal_event In scope :active, lambda {
where(archived_at: nil).left_outer_joins(:user).where.not(
user: {
id: nil
}
)
} And in def self.records(options = {})
super.active
end And when I get
I have investigated, my breakpoint is in
If I replace my
it fix the problem, but I think isn't a good solution. What do you think about this error ? Thanks 🙏 |
I can create an issue but before I would like your opinion on this problem :D |
Thanks for your note! It looks like you found a bug with this PR. We are comparing an attribute name (singular) to a table name (plural). It worked for me because I was joining through a |
Just guessing, but probably |
You compare a relation name with a table name above.
with
(It's a idea for the moment, I don't launched tests) |
Does it make more sense to match on the table name or the Rails association name? I lean toward the table name (see my comments just above), since associations could have different names but refer to the same table---but maybe the association name is okay instead. If that's what you prefer, then you should rename the local variable from |
The My suggestion
And now we compare the table names. What do you think ? |
That looks right to me! |
Thanks, I will create a PR to propose a fix ! |
When the user adds a join in
records
, it confusesget_join_arel_node
because it finds the same number of joins before & after adding a join forinclude_optional_linkage_data
(or equivalently foralways_include_*_linkage_data
).This commit falls back to searching the existing arel nodes for a compatible join and uses that if found.
Fixes #1449
All Submissions:
Bug fixes and Changes to Core Features:
Test Plan:
Reviewer Checklist: