Skip to content

Commit

Permalink
Possibly improve using different database connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Nov 7, 2014
1 parent 495f9b0 commit f858dd6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ def relation_for(object)

def type_for(attr)
return nil unless attr && attr.valid?
name = attr.arel_attribute.name.to_s
table = attr.arel_attribute.relation.table_name

schema_cache = @engine.connection.schema_cache
raise "No table named #{table} exists" unless schema_cache.table_exists?(table)
schema_cache.columns_hash(table)[name].type
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"
end
connection.schema_cache.columns_hash(table)[name].type
end

def evaluate(search, opts = {})
Expand Down

1 comment on commit f858dd6

@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 may hopefully solve issues with multiple database connections like #459, #463 and #64.

Needs tests, and if it works, should be ported to the Rails 3.0, 3.1 and 3.2 context.rb files as well.

Please sign in to comment.