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

Fix bug in filtering in Participants::Query #2003

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

ethax-ross
Copy link
Collaborator

@ethax-ross ethax-ross commented Nov 22, 2024

Jira-3798

Context

When we filter on includes with ActiveRecord the included table is filtered down to the records that match the conditional. For the Participants::Query this means when filtering by updated_since the related applications/id
changes are filtered as well as the base users. Instead, we want the users to be filtered but retain all the applications and id changes in the preloaded association.

Changes proposed in this pull request

  • Fix bug in filtering in Participants::Query

To achieve this we can instead use a subquery to find the applications/id changes updated within the timeframe and filter on the selected user_id of those.

This will be a little less efficient, but is heaps simpler than trying to do an additional join on applications/id changes to try and get Rails to retain them all after filtering.

Guidance for review

I checked the other queries for similar filtering and couldn't find anywhere else we filter on a to-many relationship that may cause the same issue.

Copy link

@ethax-ross ethax-ross marked this pull request as ready for review November 22, 2024 11:22
@ethax-ross ethax-ross requested a review from a team as a code owner November 22, 2024 11:22
@ethax-ross ethax-ross requested a review from a team November 22, 2024 11:22
@ethax-ross ethax-ross force-pushed the 3798-fix-bug-participant-applications branch from fe6180e to 3c6ef6b Compare November 22, 2024 12:32
@ethax-ross ethax-ross changed the title Fix bug in application filtering in Participants::Query Fix bug in filtering in Participants::Query Nov 22, 2024
When we filter on `includes` with ActiveRecord the included table is filtered
down to the records that match the conditional. For the `Participants::Query`
this means when filtering by `updated_since` the related applications/id
changes are filtered as well as the base users. Instead, we want the users to
be filtered but retain all the applications and id changes in the preloaded
association.

To achieve this we can instead use a subquery to find the applications/id
changes updated within the timeframe and filter on the selected `user_id` of
those.

This will be a little less efficient, but is heaps simpler than trying to do an
additional join on applications/id changes to try and get Rails to retain them
all after filtering.
Copy link

sonarcloud bot commented Nov 25, 2024

@ethax-ross ethax-ross added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit 606917b Nov 25, 2024
18 checks passed
@ethax-ross ethax-ross deleted the 3798-fix-bug-participant-applications branch November 25, 2024 13:57
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.

3 participants