From 256f75f8871b9fd464f965211f1b9f62cfc8f137 Mon Sep 17 00:00:00 2001 From: ta1kt0me Date: Tue, 11 Jul 2017 18:21:03 +0900 Subject: [PATCH] No need pass the some arugments to JoinAssociation#join_constraints in rails 5.1 refs - https://github.com/rails/rails/pull/28267 - https://github.com/rails/rails/pull/27851 --- lib/ransack/adapters/active_record/context.rb | 28 +++++++++++++------ lib/ransack/constants.rb | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 390664a4d..07477175d 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -342,15 +342,25 @@ def build_association(name, parent = @base, klass = nil) def extract_joins(association) parent = @join_dependency.join_root reflection = association.reflection - join_constraints = association.join_constraints( - parent.table, - parent.base_klass, - association, - Arel::Nodes::OuterJoin, - association.tables, - reflection.scope_chain, - reflection.chain - ) + join_constraints = if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_1 + association.join_constraints( + parent.table, + parent.base_klass, + association, + Arel::Nodes::OuterJoin, + association.tables, + reflection.scope_chain, + reflection.chain + ) + else + association.join_constraints( + parent.table, + parent.base_klass, + Arel::Nodes::OuterJoin, + association.tables, + reflection.chain + ) + end join_constraints.to_a.flatten end diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index b9144fe49..a24148176 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -46,6 +46,7 @@ module Constants CONT = 'cont'.freeze RAILS_4_1 = '4.1'.freeze + RAILS_5_1 = '5.1'.freeze RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze