diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 86ff423..3531ec2 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -22,13 +22,13 @@ module Ransack def type_for(attr) return nil unless attr && attr.valid? - name = attr.arel_attribute.name.to_s - table = attr.arel_attribute.relation.table_name - connection = attr.klass.connection - unless connection.table_exists?(table) - raise "No table named #{table} exists" + 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) + raise "No table named #{table} exists." end - connection.schema_cache.columns_hash(table)[name].type + schema_cache.columns_hash(table)[name].type end def evaluate(search, opts = {})