proper SQLmodel approach for Many to Many subqueryLoad #1508
-
First Check
Commit to Help
Example Code@router.get("/user/", response_model=List[UserReadWithClients])
async def user(limit: int = 10, offset: int=0 ):
with Session(get_engine()) as session:
statement = select(User).offset(offset).limit(limit).options(subqueryload(User.clients))
results = session.exec(statement).all()
return results DescriptionI followed the Hero and Team sample it works well but I have a many to many relationship and I get the following message Parent instance <User at 0x22b6878e880> is not bound to a Session; lazy load operation of attribute 'clients' cannot proceed I use the sqlAlchem,y orm subquery load option to fix my problem but what is the proper SQLmodel approach for many to many? Operating SystemWindows Operating System DetailsNo response SQLModel Version0.0.4 Python Version3.9.7 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I believe the approach with SQLModel is the same as with plain SQLAlchemy here. I would only consider using |
Beta Was this translation helpful? Give feedback.
I believe the approach with SQLModel is the same as with plain SQLAlchemy here.
So, your solution is valid.
I would only consider using
selectinload
instead ofsubqueryload
if there are no specific requirements that prevent you from that