module Switchman::ActiveRecord::BelongsToAssociation

Public Instance Methods

replace_keys(record, force: false) click to toggle source
Calls superclass method
# File lib/switchman/active_record/association.rb, line 40
def replace_keys(record, force: false)
  if record&.class&.sharded_column?(reflection.association_primary_key(record.class))
    foreign_id = record[reflection.association_primary_key(record.class)]
    owner[reflection.foreign_key] = Shard.relative_id_for(foreign_id, record.shard, owner.shard)
  else
    super
  end
end
shard() click to toggle source
Calls superclass method
# File lib/switchman/active_record/association.rb, line 49
def shard
  if @owner.class.sharded_column?(@reflection.foreign_key) &&
     (foreign_id = @owner[@reflection.foreign_key])
    Shard.shard_for(foreign_id, @owner.shard)
  else
    super
  end
end