Module: Switchman::ActiveRecord::BelongsToAssociation
- Defined in:
- lib/switchman/active_record/association.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
55 56 57 |
# File 'lib/switchman/active_record/association.rb', line 55 def self.included(klass) klass.send(:alias_method_chain, :replace_keys, :sharding) end |
Instance Method Details
#replace_keys_with_sharding(record) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/switchman/active_record/association.rb', line 59 def replace_keys_with_sharding(record) if record && 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 replace_keys_without_sharding(record) end end |