I'm trying to return all rows for a particular user_id.
When I run the query #1 and #2 below it only returns the first row that it finds, even though I'm specifying .all().
When I use .with_entities as in case #3, all rows are returned as expected.
I would appreciate a second pair of eyes. Thank you.
I'm using MySQLDB (5.5.47 version), Flask 0.10.1 and SQL-Alchemy 2.1 if that matters.
Returns first row only:
result = MyUserClass.query.filter_by(user_id=self.user_id).all()
This also returns first row only:
result = MyUserClass.query.filter(MyUserClass.user_id == self.user_id).all()
Works and returns all rows as expected:
MyUserClass.query.filter_by(user_id=self.user_id).with_entities(MyUserClass.myColumn).all()
used_id column was marked as the primary key column in the class definition (but not in the MySQLDB), as Martijn Pieters pointed out. Adding a new column and making it the primary key fixed the problem.
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