Module: Switchman::ActiveRecord::Associations::BelongsToAssociation
- Defined in:
- lib/switchman/active_record/associations.rb
Instance Method Summary collapse
Instance Method Details
#replace_keys(record, force: false) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/switchman/active_record/associations.rb', line 46 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 ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/switchman/active_record/associations.rb', line 55 def shard if @owner.class.sharded_column?(@reflection.foreign_key) && (foreign_id = @owner[@reflection.foreign_key]) Shard.shard_for(foreign_id, @owner.loaded_from_shard) else super end end |