Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 218
GB0 Avatar asked Feb 25 '26 22:02

GB0


1 Answers

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()

like image 183
dizzyf Avatar answered Feb 27 '26 12:02

dizzyf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!