Skip to content

Commit 0eaebb0

Browse files
Fix elasticsearch-rails sorting for Rails 5
Adapted from: elastic#618
1 parent 1576124 commit 0eaebb0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ def records
2626
# by redefining `to_a`, unless the user has called `order()`
2727
#
2828
sql_records.instance_exec(response.response['hits']['hits']) do |hits|
29-
define_singleton_method :to_a do
29+
ar_records_method_name =
30+
if defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
31+
:records
32+
else
33+
:to_a
34+
end
35+
36+
define_singleton_method(ar_records_method_name) do
3037
if defined?(::ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 4
3138
self.load
3239
else

0 commit comments

Comments
 (0)