Automatically join if filtering by relationship field
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:
- I am not sure this is something of only personal interest or if there is a need for it
- I do not have experience working with MongoDB through mongoengine, as such I still have not touched the code relative to it.
- 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.
Deploy Preview for fastapi-filter ready!
| Name | Link |
|---|---|
| Latest commit | 658fe9809c25ff8a22a5fcbdb2b1dc9d352ae39e |
| 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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
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
@@ 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%) |
:arrow_down: |
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.