Created
February 3, 2012 22:37
-
-
Save xaviershay/1733416 to your computer and use it in GitHub Desktop.
Rails connection issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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