Module: Octopus::AssociationShardTracking::InstanceMethods

Defined in:
lib/octopus/association_shard_tracking.rb

Instance Method Summary collapse

Instance Method Details

#connection_on_association=(record) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/octopus/association_shard_tracking.rb', line 8

def connection_on_association=(record)
  return unless ::Octopus.enabled?
  return if !self.class.connection.respond_to?(:current_shard) || !self.respond_to?(:current_shard)
  if !record.current_shard.nil? && !current_shard.nil? && record.current_shard != current_shard
    fail 'Association Error: Records are from different shards'
  end

  record.current_shard = self.class.connection.current_shard = current_shard if should_set_current_shard?
end