Basically I have created a database, in normal full query, this is the code I've used and the response generated.
db.session.query(User).all()
The queries generated are as below:
<User(email='[email protected]', fullname='Howard', company='howard', address='None', password='howard')>, <User(email='emailhoward', fullname='None', company='None', address='None', password='passwordhoward')>
This is logical as I'm extracting everything from the table. However, when I try to use load_only to specifically select one column, in this case, the email column. The code I've used is:
db.session.query(User).options(load_only(User.address)).all()
db.session.query(User).options(load_only('email')).all()
Both commands give me the same results:
<User(email='[email protected]', fullname='Howard', company='howard', address='None', password='howard')>,<User(email='emailhoward', fullname='None', company='None', address='None', password='passwordhoward')>
Which is extremely weird because I should be getting just one column in the query. However, when I use this:
db.session.query(User.email).select_from(User).filter_by(email=email).first()[0]
it magically returns just one column for me. I needed to use load_only as I have dynamic tables that I want to reuse the same function, rather than maintaining many sets of functions. Can anyone advise what is the issue with the load_only command, or if I'm doing something wrong?
Thank you.
See Question&Answers more detail:
os