From f18c23c5f9307a40a67eae6929eef6f77acfed09 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 17 Aug 2019 18:08:49 -0400 Subject: [PATCH] * Always put `ORDER BY` before `LIMIT`. --- angel_orm/CHANGELOG.md | 1 + angel_orm/lib/src/query.dart | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/angel_orm/CHANGELOG.md b/angel_orm/CHANGELOG.md index 1789dfa4..949584c7 100644 --- a/angel_orm/CHANGELOG.md +++ b/angel_orm/CHANGELOG.md @@ -6,6 +6,7 @@ callbacks. * Make `JoinBuilder` take `to` as a `String Function()`. This will allow ORM queries to reference their joined subqueries. * Removed deprecated `Join`, `toSql`, `sanitizeExpression`, `isAscii`. +* Always put `ORDER BY` before `LIMIT`. # 2.0.1 * Apply `package:pedantic` fixes. diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index 23e9a7fc..98f93a85 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -241,12 +241,12 @@ abstract class Query extends QueryBase { var whereClause = where.compile(tableName: includeTableName ? tableName : null); if (whereClause.isNotEmpty) b.write(' WHERE $whereClause'); - if (_limit != null) b.write(' LIMIT $_limit'); - if (_offset != null) b.write(' OFFSET $_offset'); if (_groupBy != null) b.write(' GROUP BY $_groupBy'); for (var item in _orderBy) { b.write(' ORDER BY ${item.compile()}'); } + if (_limit != null) b.write(' LIMIT $_limit'); + if (_offset != null) b.write(' OFFSET $_offset'); return b.toString(); }