Skip to content

Commit 6e99d54

Browse files
committed
fix: bug with ordering when mixing column and scope sorting
1 parent 3bacd0b commit 6e99d54

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project made by Monade Team are documented in this file. For info refer to team@monade.io
33

4+
## [0.4.2] - 2025-06-03
5+
### Fixed
6+
- Bug when mixing scope and column-based ordering
7+
48
## [0.4.1] - 2025-02-28
59
### Fixed
610
- Unsupported keys passed to `query_by` are simply ignored with a debug log, instead of an error log

lib/active_queryable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def queryable_parse_order_scope(params, query)
219219
if current_query.respond_to?(scope, true)
220220
current_query.public_send(scope, v)
221221
else
222-
current_query.order(params)
222+
current_query.order({ k => v })
223223
end
224224
end || query
225225
end

lib/active_queryable/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module ActiveQueryable
44
# @return [String] the version of the gem
5-
VERSION = '0.4.1'
5+
VERSION = '0.4.2'
66
end

spec/active_queryable/ordering_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@
1515
query = Person.query_by(sort: '-article_title', per: 'all')
1616
expect(query.to_sql).to include('ORDER BY "articles"."title" DESC')
1717
end
18+
19+
it 'order by column and scope mixed' do
20+
query = Person.query_by(sort: 'name,-article_title', per: 'all')
21+
expect(query.to_sql).to include('ORDER BY "people"."name" ASC, "articles"."title" DESC')
22+
end
1823
end

0 commit comments

Comments
 (0)