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

Automatically join if filtering by relationship field #550

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

Conversation

Kastakin
Copy link

This aims to be a first tentative approach at avoiding the need for manual joining when filtering a table.

Before the filtering itself relationship of the models are retrieved. If one of the filtering field is associated with a relationship and it contains values not only null values the corresponding table is joined. This accommodates for nested filters and tables connected through a secondary table.

I call this change tentative for three main reasons:

  1. I am not sure this is something of only personal interest or if there is a need for it
  2. I do not have experience working with MongoDB through mongoengine, as such I still have not touched the code relative to it.
  3. Some tests are failing due to warning to cartesian products between columns. In my use case this does not seem to generate wrong results, but I am not 100% sure on the best course of action could be in this case to avoid the warning altogether, as such I have not changed the tests yet to pass. Some are still failing due to the aforementioned warning.

Copy link

netlify bot commented Jan 29, 2024

Deploy Preview for fastapi-filter ready!

Name Link
🔨 Latest commit 658fe98
🔍 Latest deploy log https://app.netlify.com/sites/fastapi-filter/deploys/6613e726e8776100080dda54
😎 Deploy Preview https://deploy-preview-550--fastapi-filter.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Kastakin Kastakin marked this pull request as draft February 1, 2024 15:35
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 98.17%. Comparing base (e0f2fa8) to head (658fe98).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##              main     #550      +/-   ##
===========================================
- Coverage   100.00%   98.17%   -1.83%     
===========================================
  Files            6        6              
  Lines          193      219      +26     
===========================================
+ Hits           193      215      +22     
- Misses           0        4       +4     
Files Coverage Δ
fastapi_filter/contrib/sqlalchemy/filter.py 94.87% <85.71%> (-5.13%) ⬇️

@Kastakin Kastakin marked this pull request as ready for review February 2, 2024 11:14
@Kastakin
Copy link
Author

Kastakin commented Feb 2, 2024

I have looked a bit more into what was causing the tests to fail and reworked everything to pass it.

Nested behavior was not tested yet. I actually think it is possible to modify what it is already in place slightly to test nested filters too (e.g., the city column could become another table connected to the address one).

In my application I am already filtering in both nested and many-to-many relationships without any evidence of problems.

I can commit to the task more if it is something actually of interest.

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