问题描述:

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

相关阅读:
Top