Module: Switchman::ActiveRecord::Associations::ForeignAssociation

Defined in:
lib/switchman/active_record/associations.rb

Instance Method Summary collapse

Instance Method Details

#set_owner_attributes(record) ⇒ Object

significant change:

* transpose the key to the correct shard


63
64
65
66
67
68
69
70
71
# File 'lib/switchman/active_record/associations.rb', line 63

def set_owner_attributes(record) # rubocop:disable Naming/AccessorMethodName
  return if options[:through]

  key = owner._read_attribute(reflection.join_foreign_key)
  key = Shard.relative_id_for(key, owner.shard, shard)
  record._write_attribute(reflection.join_primary_key, key)

  record._write_attribute(reflection.type, owner.class.polymorphic_name) if reflection.type
end