Repository navigation
Replies: 1 comment
|
from sqlalchemy.orm import selectinload
from sqlmodel import select
statement = (
select(Entidad)
.where(Entidad.ent_idtipoentidad == tipo)
.options(selectinload(Entidad.your_relationship))
)
return self.db.exec(statement).all()Replace This is eager loading: related rows are fetched in additional batched SELECTs rather than one lazy query per parent. A plain If the option still fails, share the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
It turns out that to display related data from another table I have to use selectinload() for lazy loading and not make the slow request when there is too much data. In SQLAlchemy it is imported with from sqlalchemy.orm import selectinload. But I am going to do the same in SQLModel and that method does not work, only the join() appears. I fully understand that SQLModel is a base model built on top of SQLAlchemy, but it would be great if they integrated that method, it helps a lot.
Operating System
Windows
Operating System Details
Windows 11 HOME
SQLModel Version
0.0.14
Python Version
3.13.1
Additional Context
No response
All reactions