GB0
GB0

Reputation: 39

SQLAlchemy ORM Load Cols Only not working

I'm using query like this: user = User.query.options(load_only("email", "name")).filter(and_(User.id == id, User.status == 1)).first()

I want to get only email and name column as an User object. But it returns all columns. I can't find any solutions. Can anybody help? Thanks

Upvotes: 3

Views: 1768

Answers (1)

dizzyf
dizzyf

Reputation: 3693

If you're using a database session, you can simply specify the columns directly.

session.query(User.email, User.name).filter(and_(User.id == id, User.status == 1)).first()

Upvotes: 1

Related Questions