sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Add config option to load relationship fields.

Open busykoala opened this issue 3 years ago • 13 comments

Close https://github.com/tiangolo/sqlmodel/issues/444

Due to the recursive loading problem loading relations is not yet possible. This change introduces the config option 'include_relations' to also load specifically chosen relations.

For the current use case nothing changes unless the user specifically sets fields to be included (and carefully considers the risks of circular includes). The option is very valuable if the table design contains many 1:n relations.

Additionally, if the new config option was used with fastapi the tests show that the relation additionally has to be set to sa_relationship_kwargs={"lazy": "selectin"}), while the relations will not be returned otherwise.

busykoala avatar Sep 11 '22 12:09 busykoala

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ea79c47) 98.49% compared to head (962c9c8) 97.84%. Report is 121 commits behind head on main.

:exclamation: Current head 962c9c8 differs from pull request most recent head cbc9a0d. Consider uploading reports for the commit cbc9a0d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #445      +/-   ##
==========================================
- Coverage   98.49%   97.84%   -0.66%     
==========================================
  Files         185      188       +3     
  Lines        5856     6450     +594     
==========================================
+ Hits         5768     6311     +543     
- Misses         88      139      +51     
Files Coverage Δ
sqlmodel/main.py 85.42% <100.00%> (ø)
tests/test_relation_resolution.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 11 '22 12:09 codecov[bot]

📝 Docs preview for commit 96d8163bbe1a69cfedd59d12f1f6cc5dcabc30d9 at: https://631dd936753845213d1e2387--sqlmodel.netlify.app

github-actions[bot] avatar Sep 11 '22 12:09 github-actions[bot]

📝 Docs preview for commit 84f63cf16fa3edfc73900ebb71aca8408f54b606 at: https://631dda323fbe07200d52088f--sqlmodel.netlify.app

github-actions[bot] avatar Sep 11 '22 12:09 github-actions[bot]

📝 Docs preview for commit 8a5ffcccf55b48b1a03a27fbbc3b88dbb2f545cd at: https://631ddb6ebb7dd71b7b02620a--sqlmodel.netlify.app

github-actions[bot] avatar Sep 11 '22 12:09 github-actions[bot]

📝 Docs preview for commit f6dc33940a7536e47ab8fc78982a4fb449a30601 at: https://631ddc07663389246842205f--sqlmodel.netlify.app

github-actions[bot] avatar Sep 11 '22 13:09 github-actions[bot]

📝 Docs preview for commit 962c9c8f036918d6875fc73d20ad3d17aa2ffc75 at: https://631ddeff5fa59526a8ff8fe5--sqlmodel.netlify.app

github-actions[bot] avatar Sep 11 '22 13:09 github-actions[bot]

bump

kennedy avatar Sep 26 '22 05:09 kennedy

📝 Docs preview for commit 51aa03f72ad62839027178fb1053edcc4ed37792 at: https://639ce02ba12b8e02ba9de2b6--sqlmodel.netlify.app

github-actions[bot] avatar Dec 16 '22 21:12 github-actions[bot]

📝 Docs preview for commit b408fa9fa300033cfae42ce55d32df1b883cd9ca at: https://f3eafa08.sqlmodel.pages.dev

github-actions[bot] avatar Aug 14 '23 23:08 github-actions[bot]

📝 Docs preview for commit cbc9a0d2d9b9dd08e8ed074954983c2639d4c294 at: https://2ea088ba.sqlmodel.pages.dev

github-actions[bot] avatar Nov 12 '23 23:11 github-actions[bot]

That'd be very helpful and will reduce duplicated code. Any plans to merge this PR any time soon? :pray:

emp-l avatar Jan 19 '24 04:01 emp-l