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
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With