Skip to content

Commit 06b40a4

Browse files
authored
Merge pull request #886 from mateuscruz/update-establish-connection-override
Move lazy loading from Base to ConnectionAdapters::ConnectionHandler
2 parents 7504d8a + fe91905 commit 06b40a4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/activerecord-import/import.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,20 @@ def bulk_import(*args, &block)
251251
alias import bulk_import unless respond_to? :import
252252
end
253253

254-
module ActiveRecord::Import::Connection
255-
def establish_connection(args = nil)
256-
conn = super(args)
257-
ActiveRecord::Import.load_from_connection_pool connection_pool
258-
conn
254+
module ActiveRecord::Import::ConnectionHandler
255+
def establish_connection(*args, **kwargs, &block)
256+
pool = super(*args, **kwargs, &block)
257+
ActiveRecord::Import.load_from_connection_pool pool
258+
pool
259259
end
260260
end
261261

262+
class ActiveRecord::ConnectionAdapters::ConnectionHandler
263+
prepend ActiveRecord::Import::ConnectionHandler
264+
end
265+
262266
class ActiveRecord::Base
263267
class << self
264-
prepend ActiveRecord::Import::Connection
265-
266268
# Returns true if the current database connection adapter
267269
# supports import functionality, otherwise returns false.
268270
def supports_import?(conn = nil)

0 commit comments

Comments
 (0)