Skip to content

Commit

Permalink
Replace deprecated AR table_exists? API in Rails 5.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonatack committed Sep 24, 2015
1 parent 320cd95 commit c9d2297
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

1 comment on commit c9d2297

@jonatack
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change from Rails commit rails/rails@152b85f.

Please sign in to comment.