Hi all,
For the following code, which uses tables for CalendarEntry, Match, and Team entities:
team_alias1 = aliased(Team)
team_alias2 = aliased(Team)
matches_query = session\
.query(CalendarEntry.match_id, Match, team_alias1, team_alias2)\
.join(Match, CalendarEntry.match_id == Match.id)\
.filter(CalendarEntry.user_id == client_id)\
.limit(2)
When setting echo=True and running my unit tests in SQLite, I get a query that looks like:
SELECT "CalendarEntries".match_id AS "CalendarEntries_match_id", "Matches".id AS "Matches_id", ... etc
WHERE "CalendarEntries".user_id = ? LIMIT ? OFFSET ?
(1, 2, 0)
Which correctly returns 2 CalendarEntry objects. However, if I no longer chain the call to limit immediately, but put it in its own statement, like so:
matches_query = session\
.query(CalendarEntry.match_id, Match, team_alias1, team_alias2)\
.join(Match, CalendarEntry.match_id == Match.id)\
.filter(CalendarEntry.user_id == client_id)
matches_query.limit(2)
Then I get a query without a LIMIT, which returns all CalendarEntry objects:
SELECT "CalendarEntries".match_id AS "CalendarEntries_match_id", "Matches".id AS "Matches_id", ... etc
WHERE "CalendarEntries".user_id = ?
(1,)
Can someone explain what's going on, and how to fix this?
Thanks,
Mike