Module: Octopus::AssociationShardTracking::InstanceMethods

Defined in:
lib/octopus/association_shard_tracking.rb

Instance Method Summary collapse

Instance Method Details

#connection_on_association=(record) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/octopus/association_shard_tracking.rb', line 26

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.to_s != current_shard.to_s
    raise MismatchedShards.new(record, current_shard)
  end

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