dev/core#4821 - APIv4: Allow custom field to reference value in bridge joins #29325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Fixes https://lab.civicrm.org/dev/core/-/issues/4821
Before
SQL error when trying to compare a field value in the on condition of a custom field.
After
Query works correctly.
Technical Details
When part of a bridge join there are two ways to get at the
id
of the joined entity. E.g. when joining Activity through ActivityContact, you could access the Activity id field either viacivicrm_activity.id
or viacivicrm_activity_contact.activity_id
. Custom fields were trying to join using the normal way ofcivicrm_activity.id
but that fails if the custom field is getting joined prior to the activity table join. So instead of joining custom fields the normal way, they need to be joined to the bridge table.Also includes follow-up to b367821 which adds metadata about these joins so the values are discoverable and not always assumed to match the name of the entity table (usually they do, but they don't have to).