Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created February 3, 2012 22:37
Show Gist options
  • Save xaviershay/1733416 to your computer and use it in GitHub Desktop.
Save xaviershay/1733416 to your computer and use it in GitHub Desktop.
Rails connection issue
# Old way, creates too many connections, breaks transactional fixtures.
# More broken on 3.2 than 3.1, didn't identify exact change though.
#
# Our suite was passing on 3.1 by accident when we initially tried to upgrade to 3.2,
# which broke everything. Since then, have added new specs that exposed the problem in 3.1.
#
# This is probably not a rails bug, but was surprising.
module OtherModel
def self.included(klass)
klass.instance_eval do
establish_connection :"other_#{Rails.env}"
end
end
end
class User < ActiveRecord::Base
include OtherModel
end
# New way, use inheritance rather than a mixin.
# Works as expected.
class OtherModel < ActiveRecord::Base
self.abstract_class = true
establish_connection :"other_#{Rails.env}"
end
class User < OtherModel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment