Fix include_optional_linkage_data with joins#1450
Fix include_optional_linkage_data with joins#1450lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
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! |
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_eventIn has_one :patient_enrolled_journal_event,
exclude_links: :default,
foreign_key_on: :related,
relation_name: :patient_enrolled_journal_eventIn scope :active, lambda {
where(archived_at: nil).left_outer_joins(:user).where.not(
user: {
id: nil
}
)
}And in def self.records(options = {})
super.active
endAnd 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 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.
When the user adds a join in
records, it confusesget_join_arel_nodebecause 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 cerebris/jsonapi-resources#1449
All Submissions:
Bug fixes and Changes to Core Features:
Test Plan:
Reviewer Checklist: