Ruby on Rails
Thursday, July 29, 2010
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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment