Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Created June 20, 2012 09:35
Show Gist options
  • Save jhjguxin/2959066 to your computer and use it in GitHub Desktop.
Save jhjguxin/2959066 to your computer and use it in GitHub Desktop.
rails has_many through and Multiple databases causing SQLite::BusyException
class User < ActiveRecord::Base
establish_connection "users_#{Rails.env}" # use alternate DB
has_many :memberships
has_many :groups, through => :memberships
end
class Group < ActiveRecord::Base
establish_connection "users_#{Rails.env}" # use alternate DB
has_many :memberships
has_many :users, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :group
belongs_to :user
# validations stuff
establish_connection "users_#{Rails.env}" # use alternate DB
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment