From ee7a6d5f04e6fea864867a21734df85559c3ba67 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 2 Apr 2019 19:30:42 -0400 Subject: [PATCH] Fix order by --- angel_orm/CHANGELOG.md | 3 +++ angel_orm/lib/src/query.dart | 2 +- angel_orm/pubspec.yaml | 2 +- angel_orm_generator/test/belongs_to_test.dart | 6 ++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/angel_orm/CHANGELOG.md b/angel_orm/CHANGELOG.md index e9e08aa5..855d219b 100644 --- a/angel_orm/CHANGELOG.md +++ b/angel_orm/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-dev.24 +* Fix a bug that caused syntax errors on `ORDER BY`. + # 2.0.0-dev.23 * Add `@ManyToMany` annotation, which builds many-to-many relations. diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index c9196ad9..e5bae47d 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -344,7 +344,7 @@ abstract class Query extends QueryBase { 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(' ${item.compile()}'); + for (var item in _orderBy) b.write(' ORDER BY ${item.compile()}'); return b.toString(); } diff --git a/angel_orm/pubspec.yaml b/angel_orm/pubspec.yaml index d89d0732..53b11fd3 100644 --- a/angel_orm/pubspec.yaml +++ b/angel_orm/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm -version: 2.0.0-dev.23 +version: 2.0.0-dev.24 description: Runtime support for Angel's ORM. Includes base classes for queries. author: Tobe O homepage: https://github.com/angel-dart/orm diff --git a/angel_orm_generator/test/belongs_to_test.dart b/angel_orm_generator/test/belongs_to_test.dart index 92fab1c6..c792e8c4 100644 --- a/angel_orm_generator/test/belongs_to_test.dart +++ b/angel_orm_generator/test/belongs_to_test.dart @@ -110,6 +110,12 @@ main() { expect(author.id, jkRowling.id); expect(author.name, jkRowling.name); }); + + test('order by', () async { + var query = AuthorQuery()..orderBy(AuthorFields.name, descending: true); + var authors = await query.get(executor); + expect(authors, [jkRowling, jameson]); + }); }); test('insert sets relationship', () {