Module: Octopus::Association::InstanceMethods

Defined in:
lib/octopus/association.rb

Instance Method Summary collapse

Instance Method Details

#set_connection_on_association(record) ⇒ Object



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

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

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