You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
I have a basic one to many relationship. Releases have Tracks via a release_id property on Track. Track has a sort_order property that's an int used to sort the tracks. tracks should always be sorted by sort_by.
In this example I'm sorting the tracks after the query is executed. This works but there are some issues:
This seems like a non-optimal solution and I would think it would be preferable to do the sort as part of the query somehow.
The Track relationship is not the only nested relationship I need to sort like this; there are also labels and artists that need to be returned in order and I'd like to avoid needing a for loop for each one.
### Description
Sorting nested relationships when querying model.
### Operating System
macOS
### Operating System Details
_No response_
### SQLModel Version
0.0.20
### Python Version
3.10.14
### Additional Context
_No response_
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
I have a basic one to many relationship.
Releases
haveTrack
s via arelease_id
property onTrack
.Track
has asort_order
property that's an int used to sort the tracks. tracks should always be sorted bysort_by
.The models look something like this:
And my endpoint looks like this:
In this example I'm sorting the tracks after the query is executed. This works but there are some issues:
Beta Was this translation helpful? Give feedback.
All reactions