Version that works in Rails 3 too.

In Rails 3, #establish_connection is defined directly on
ActiveRecord::Base, not on a module, causing the ancestor chain order to
be wrong. #prepend covers it in both cases.