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

SearchKit - proper EntityRef joins #26192

Merged
merged 1 commit into from
May 11, 2023

Conversation

MegaphoneJon
Copy link
Contributor

Overview

#25927 improved the state of EntityRef custom fields in SearchKit, but didn't allow displaying fields in the joined table other than the primary key. This allows a proper join to EntityRef records.

To replicate

  • create an EntityRef custom field on Contributions referencing a Contact.
  • Try to pull in the middle name of the contact, or their membership info.

Before

You can see only the ID and pseudoconstant lookup of the EntityRef.
Selection_1882

After

You can join fully to the EntityRef record, and join to the referenced record as usual.
Selection_1881

Comments

This join is in one direction only - because I don't see a good way to join to a custom field. You'd have to join from Contact to Contribution, then Contribution to custom field table.

@civibot
Copy link

civibot bot commented May 10, 2023

(Standard links)

@civibot civibot bot added the master label May 10, 2023
@@ -366,6 +366,24 @@ public static function getJoins(array $allowedEntities):array {
}
}
}
// Custom EntityRef joins
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MegaphoneJon did you happen to notice what in the above code stops it from working for custom fields already? I would have thought their metadata would have triggered it to include them since they do declare a fk_entity like other fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw I'm not sure which of places you mean by "above code", but:

  • Line 329 references fk_entity but is in an if ($bridge) conditional.
  • Lines 273-319 handle non-bridge joins, but only loops through $references. Since $references comes from $dao::getReferenceColumns() it doesn't handle custom fields.
  • addImplicitFKFields() works correctly (because of your work on SearchKit - Fix handling of new Custom EntityReference fields #25927), but only getJoins() modifies $joins. This leaves a scenario where you can hack civicrm_saved_search.api_params to retrieve the fields you want - but you can't select the joins in the SK UI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Ok.
Thanks for adding a test.

@colemanw colemanw merged commit 6b605a3 into civicrm:master May 11, 2023
@colemanw colemanw changed the title proper EntityRef joins SearchKit - proper EntityRef joins May 11, 2023
@MegaphoneJon MegaphoneJon deleted the entity-ref-joins branch May 11, 2023 02:16
@jensschuppe
Copy link
Contributor

This is planned to be released with 5.63.0, just noting for documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants