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


75
76
77
78
79
80
81
82
83
# File 'lib/switchman/active_record/associations.rb', line 75

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