From c9d2297ff72401196e044a822e26f0b136186b6c Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 24 Sep 2015 13:46:38 +0200 Subject: [PATCH] Replace deprecated AR `table_exists?` API in Rails 5. A propos, it's about time we simplify context.rb into separate files for Active Record 4.x and 5.0 like we did for 3.x, which will enable removing a fair number of conditionals. --- lib/ransack/adapters/active_record/context.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index c21580615..dc1742973 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -25,7 +25,7 @@ def type_for(attr) name = attr.arel_attribute.name.to_s table = attr.arel_attribute.relation.table_name schema_cache = @engine.connection.schema_cache - unless schema_cache.table_exists?(table) + unless schema_cache.send(database_table_exists?, table) raise "No table named #{table} exists." end schema_cache.columns_hash(table)[name].type @@ -134,6 +134,14 @@ def alias_tracker private + def database_table_exists? + if ::ActiveRecord::VERSION::MAJOR >= 5 + :data_source_exists? + else + :table_exists? + end + end + def get_parent_and_attribute_name(str, parent = @base) attr_name = nil