mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Merge branch 'yujideveloper-bugfix/fix-multiple-database-connection'
This commit is contained in:
commit
7f6525e996
4 changed files with 38 additions and 3 deletions
|
@ -27,7 +27,7 @@ module Ransack
|
|||
return nil unless attr && attr.valid?
|
||||
name = attr.arel_attribute.name.to_s
|
||||
table = attr.arel_attribute.relation.table_name
|
||||
schema_cache = ::ActiveRecord::Base.connection.schema_cache
|
||||
schema_cache = self.klass.connection.schema_cache
|
||||
unless schema_cache.send(database_table_exists?, table)
|
||||
raise "No table named #{table} exists."
|
||||
end
|
||||
|
@ -290,7 +290,7 @@ module Ransack
|
|||
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
||||
end
|
||||
else
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, relation.table.name, join_list)
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
|
||||
join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
|
||||
join_nodes.each do |join|
|
||||
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
|
||||
|
@ -333,7 +333,7 @@ module Ransack
|
|||
)
|
||||
found_association = jd.join_root.children.last
|
||||
else
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(::ActiveRecord::Base.connection, parent.table.name, [])
|
||||
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, [])
|
||||
jd = JoinDependency.new(
|
||||
parent.base_klass,
|
||||
parent.base_klass.arel_table,
|
||||
|
|
|
@ -18,6 +18,13 @@ module Ransack
|
|||
expect(subject.object).to be_an ::ActiveRecord::Relation
|
||||
end
|
||||
|
||||
context "multiple database connection" do
|
||||
it "does not raise error" do
|
||||
expect { Person.ransack(name_cont: "test") }.not_to raise_error
|
||||
expect { SubDB::OperationHistory.ransack(people_id_eq: 1) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with scopes' do
|
||||
before do
|
||||
allow(Person)
|
||||
|
|
|
@ -37,6 +37,7 @@ RSpec.configure do |config|
|
|||
line = '=' * message.length
|
||||
puts line, message, line
|
||||
Schema.create
|
||||
SubDB::Schema.create
|
||||
end
|
||||
|
||||
config.before(:all) { Sham.reset(:before_all) }
|
||||
|
|
|
@ -261,3 +261,30 @@ module Schema
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
module SubDB
|
||||
class Base < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
establish_connection(
|
||||
adapter: 'sqlite3',
|
||||
database: ':memory:'
|
||||
)
|
||||
end
|
||||
|
||||
class OperationHistory < Base
|
||||
end
|
||||
|
||||
module Schema
|
||||
def self.create
|
||||
s = ::ActiveRecord::Schema.new
|
||||
s.instance_variable_set(:@connection, SubDB::Base.connection)
|
||||
s.verbose = false
|
||||
s.define({}) do
|
||||
create_table :operation_histories, force: true do |t|
|
||||
t.string :operation_type
|
||||
t.integer :people_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue