当前位置: 动力学知识库 > 问答 > 编程问答 >

python - 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

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: