Skip to content

feat: EXPOSED-462 Filtering on entity references #2472

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

natri0
Copy link

@natri0 natri0 commented May 1, 2025

Description

Summary of the change: Adds a way to filter referrersOn/optionalReferrersOn

Detailed description:

  • What: Two new methods for the DAO API: View.referrersOn and View.optionalReferrersOn.
  • Why: This seems like a niche yet requested feature that has been stale for 9 months according to the YouTrack issue.
  • How:
    • moved the condition generating logic in Referrers to a separate method subclasses can override
    • added a new ViewReferrers class representing a referrersOn with a View left-hand side parameter (as opposed to EntityClass)

Type of Change

Please mark the relevant options with an "X":

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

EXPOSED-462

natri0 added 5 commits April 28, 2025 00:17
Now it's possible to additionally filter the child entities on a one-to-many relationship by using a `View` as the left-hand-side parameter for `referrersOn`:

    val kids by User.view { Users.age less 18 } referrersOn Users.city

This example was added to SamplesDao to show off the new feature.

FIXME: tried adding eager loading but it seems like there's no way to filter entities based on the Op, so might for now be impossible.

TODO: write tests
I don't know how to actually make the caching work there. :(
Seems like we'd have to evaluate the custom WHERE clause from the View and filter based on that, but it doens't look like there's any way to evaluate a Op<Boolean>.
@natri0
Copy link
Author

natri0 commented May 1, 2025

though I didn't figure out how caching is supposed to work in this case, so if anyone has any thoughts would be thankful.

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

Successfully merging this pull request may close these issues.

1 participant