Prevent garbage collection of the joined record #1217
Unanswered
romantolkachyov
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I'm using a select with join to retrieve related model.
After I return parent model from the repository method, the child model garbage collected (and it sound reasonable). So
patient.user
will lead to additional query to the database (or exception in my case cause I use async session).To solve this, I store related model to the class property
_loaded_related
to preserve reference and prevent garbage collection.Are there any other clear way to do so? Don't want to return both records from the repository method cause I want a clear interface (and will still have to deal with gc above on the stack anyway).
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.22
Python Version
Python 3.12.7
Additional Context
I believe there is no issue with SQLModel of SQLAlchemy, just trying to find a better approach.
Beta Was this translation helpful? Give feedback.
All reactions