diff --git a/lib/octopus/model.rb b/lib/octopus/model.rb index 29faf70a..11a46fe9 100644 --- a/lib/octopus/model.rb +++ b/lib/octopus/model.rb @@ -98,8 +98,9 @@ def hijack_methods around_save :run_on_shard, :unless => -> { self.class.custom_octopus_connection } after_initialize :set_current_shard + cattr_accessor :custom_octopus_connection + class << self - attr_accessor :custom_octopus_connection attr_accessor :custom_octopus_table_name alias_method_chain :connection, :octopus diff --git a/spec/octopus/model_spec.rb b/spec/octopus/model_spec.rb index d9881439..516c65b4 100644 --- a/spec/octopus/model_spec.rb +++ b/spec/octopus/model_spec.rb @@ -263,6 +263,12 @@ expect(CustomConnection.connection.current_database).to eq('octopus_shard_2') end + it 'reuses parent model connection' do + klass = Class.new(CustomConnection) + + expect(klass.connection).to be klass.connection + end + it 'should not mess with custom connection table names' do expect(Advert.connection.current_database).to eq('octopus_shard_1') Advert.create!(:name => 'Teste')