Skip to content

[MODEL] Fix sort order on ActiveRecord >= 5 #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def order(*args)
# Redefine the `to_a` method to the original one
#
sql_records.instance_exec do
define_singleton_method(:to_a) do
ar_records_method_name = :to_a
ar_records_method_name = :records if defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5

define_singleton_method(ar_records_method_name) do
if defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 4
self.load
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ def as_indexed_json(options = {})

if defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 4
assert_equal 'Testing Coding', response.records.order(title: :desc).first.title
assert_equal 'Testing Coding', response.records.order(title: :desc)[0].title
else
assert_equal 'Testing Coding', response.records.order('title DESC').first.title
assert_equal 'Testing Coding', response.records.order('title DESC')[0].title
end
end

Expand Down