Connection_pool with_connection strange behaviour - ActiveRecord 2.3.8

I noticed some strange behaviour with connection_pool.with_connection
and it’s probably because I am not understanding the proper usage. If
I call with_connection, it seems to me that the connection within the
block is not used with the ActiveRecord methods. First a simple ==
comparison.

jruby-1.5.1 > ActiveRecord::Base.connection_pool.with_connection{|c|
ActiveRecord::Base.connection==c }
=> false

Then examining the number of active connections after using the
with_connection method:

=>
{“ActiveRecord
::Base”=>#ActiveRecord::ConnectionAdapters::ConnectionPool:0x105b3e5d}
jruby-1.5.1 >
ActiveRecord::Base.connection_pool.instance_eval{ @checked_out.length }
=> 0
jruby-1.5.1 > ActiveRecord::Base.connection_pool.with_connection{ |c|
EmailAccount.last }
jruby-1.5.1 >
ActiveRecord::Base.connection_pool.instance_eval{ @checked_out.length }
=> 1

I found this lighthouse ticket
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1752
, but it seems to have been resolved. I am using ActiveRecord 2.3.8.

thx.

-karl

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs