Rails 5 / Arel 5 compatibility patch
The Arel API changed in the following commit 2 weeks ago and broke Ransack compatibility with Arel and Rails master. This is a quick patch. We should probably set up separate context files for 4.2 and 5.0 like with 3.0-4.1.
This commit is contained in:
parent
7961d807a9
commit
3c56371d8f
4
Gemfile
4
Gemfile
|
@ -5,8 +5,8 @@ gem 'rake'
|
|||
|
||||
rails = ENV['RAILS'] || 'master'
|
||||
|
||||
if rails[0,3] == '4.2' || rails == 'master'
|
||||
gem 'arel', github: 'rails/arel', branch: 'master'
|
||||
if %w(5.0 4.2).include?(rails[0,3]) || rails == 'master'
|
||||
gem 'arel', github: 'rails/arel'
|
||||
end
|
||||
|
||||
gem 'polyamorous', '~> 1.1'
|
||||
|
|
|
@ -94,7 +94,12 @@ module Ransack
|
|||
# JoinDependency to track table aliases.
|
||||
#
|
||||
def join_sources
|
||||
base = Arel::SelectManager.new(@object.engine, @object.table)
|
||||
base =
|
||||
if ::ActiveRecord::VERSION::MAJOR >= 5
|
||||
Arel::SelectManager.new(@object.engine)
|
||||
else
|
||||
Arel::SelectManager.new(@object.engine, @object.table)
|
||||
end
|
||||
joins = @join_dependency.join_constraints(@object.joins_values)
|
||||
joins.each do |aliased_join|
|
||||
base.from(aliased_join)
|
||||
|
@ -202,8 +207,13 @@ module Ransack
|
|||
.map { |x| x.strip }
|
||||
.uniq
|
||||
|
||||
join_list = relation.send :custom_join_ast,
|
||||
relation.table.from(relation.table), string_joins
|
||||
join_list =
|
||||
if ::ActiveRecord::VERSION::MAJOR >= 5
|
||||
relation.send :custom_join_ast, relation.table.from, string_joins
|
||||
else
|
||||
relation.send :custom_join_ast,
|
||||
relation.table.from(relation.table), string_joins
|
||||
end
|
||||
|
||||
join_dependency = JoinDependency.new(
|
||||
relation.klass, association_joins, join_list
|
||||
|
|
Loading…
Reference in New Issue