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

APIv4 - Use subquery to LEFT JOIN via a bridge entity #19825

Merged
merged 3 commits into from
Mar 21, 2021

Conversation

colemanw
Copy link
Member

Overview

Per https://lab.civicrm.org/dev/core/-/issues/2438

Fixes the ability to do "Without" conditions in SearchKit when a bridge table is used (e.g. EntityTag or RelationshipCache).

Before

Bridge entities are supposed to be transparent in APIv4, but when LEFT joining, an artifact of the double-join would give extraneous results.

After

Uses a subquery to achieve a single LEFT JOIN making the bridge table invisible to the api user.

@civibot
Copy link

civibot bot commented Mar 18, 2021

(Standard links)

@civibot civibot bot added the master label Mar 18, 2021
@colemanw colemanw force-pushed the api4BridgeJoinSubquery branch from 06381b2 to 9a12b0d Compare March 18, 2021 12:51
@eileenmcnaughton
Copy link
Contributor

@colemanw so I shouldn't test this until you have added another commit?

@colemanw
Copy link
Member Author

I just pushed up a new feature into this PR where you can select "Without" as a join type in SearchKit. I'll add another commit soon with a test and an upgrade script, but feel free to do an r-run at this point :)

Bridge entities are supposed to be transparent in APIv4, but when LEFT joining,
an artifact of the double-join would give extraneous results.
@colemanw colemanw force-pushed the api4BridgeJoinSubquery branch from 3357a25 to 92cb17f Compare March 21, 2021 21:29
@eileenmcnaughton
Copy link
Contributor

OK - I had a bit of trouble testing this but there reasons were in the end UI issues unrelated to this PR - e.g inadvertently selecting the tag id from the first join in the second join

image

@eileenmcnaughton
Copy link
Contributor

So my upgrade test passed this time

Before
image

{"version":4,"select":["id","display_name"],"orderBy":[],"where":[],"groupBy":[],"join":[["Contribution AS Contact_Contribution_contact_id_01",true,["id","=","Contact_Contribution_contact_id_01.contact_id"]]],"having":[]}

After

{"version":4,"select":["id","display_name"],"orderBy":[],"where":[],"groupBy":[],"join":[["Contribution AS Contact_Contribution_contact_id_01","INNER",["id","=","Contact_Contribution_contact_id_01.contact_id"]]],"having":[]}

image

One thing I would note is we should probably make extension upgrades visible to run from the civicrm/upgrade screen or run automatically as I rather failed to spot that I needed a separate process

MOP

@colemanw colemanw merged commit 5271fc9 into civicrm:master Mar 21, 2021
@colemanw colemanw deleted the api4BridgeJoinSubquery branch March 21, 2021 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants