APIv4 - Prevent api adding default join conditions when it shouldn't #19993
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 a bug in SearchKit where e.g. joining email to related contact returns no emails.
Before
This search returns no emails:
http://wp.demo/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fadmin%2Fsearch#/create/Contact?params=%7B%22version%22:4,%22select%22:%5B%22id%22,%22display_name%22,%22Contact_RelationshipCache_Contact_01.display_name%22,%22Contact_RelationshipCache_Contact_01_Contact_Email_contact_id_01.email%22%5D,%22orderBy%22:%7B%7D,%22where%22:%5B%5D,%22groupBy%22:%5B%5D,%22join%22:%5B%5B%22Contact%20AS%20Contact_RelationshipCache_Contact_01%22,%22INNER%22,%22RelationshipCache%22,%5B%22id%22,%22%3D%22,%22Contact_RelationshipCache_Contact_01.far_contact_id%22%5D%5D,%5B%22Email%20AS%20Contact_RelationshipCache_Contact_01_Contact_Email_contact_id_01%22,%22LEFT%22,%5B%22Contact_RelationshipCache_Contact_01.id%22,%22%3D%22,%22Contact_RelationshipCache_Contact_01_Contact_Email_contact_id_01.contact_id%22%5D%5D%5D,%22having%22:%5B%5D%7D
After
Emails are returned as they should be.
Technical Details
When adding an explicit join, the api will search for a default condition unlessan fk field has been explicitly set. This fixes an error when the api thought no fk field was present when it actually was.
The alias was being added when it should have been removed. Oops.