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)\
.join(team_alias1, Match.team1_id == team_alias1.id)\
.join(team_alias2, Match.team2_id == team_alias2.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)\
.join(team_alias1, Match.team1_id == team_alias1.id)\
.join(team_alias2, Match.team2_id == team_alias2.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

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/AsqSgGMMBxoJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to