Reputation: 33
Been messing around with SQLalchemy and Flask and have run up into a problem that I can't find good documentation on.
I need to query for the email of a specific user, but I can't figure the right combination of filter and select the specific column.
I've tried:
user = User.query.filter(User.username == currentuser).email
user = User.query(User.email).filter(User.username == currentuser)
user = User.query.filter(User.username == currentuser, User.email)
user = User.query.filter(User.email, User.username == currentuser)
But I'm not able to get the results I want.
Upvotes: 2
Views: 7584
Reputation: 663
Pretty sure
user = User.query.filter(User.username == currentuser).email
does not actually execute the query, you have to do something like
user = User.query.filter(User.username == currentuser).first().email
as per http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.first
Note, the statement above will fail if the user doesn't exist as first() will return None.
Upvotes: 6