Posts tagged: orm

All posts with the tag "orm"

1 posts latest post 2024-01-12

Today I was running some sqlmodel queries through the sqlalchemy orm. Admittedly I’ve not done enough orm queries before, and I’ve done quite a bit of raw sql. I was trying to get objects from two separate models that had relationships setup.

session.query(User, Images).where(User.id == 3).all()

It is incredibly slow, and gives me the following warning.

SELECT statement has a cartesian product between FROM element(s)

What I learned from the SQLModel docs is that you should give it a join to correct this and go much faster.