Module: Switchman::ActiveRecord::Association
- Defined in:
- lib/switchman/active_record/association.rb
Instance Method Summary collapse
- #build_record(*args) ⇒ Object
- #creation_attributes ⇒ Object
- #load_target ⇒ Object
- #scope ⇒ Object
- #shard ⇒ Object
Instance Method Details
#build_record(*args) ⇒ Object
10 11 12 |
# File 'lib/switchman/active_record/association.rb', line 10 def build_record(*args) self.shard.activate { super } end |
#creation_attributes ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/switchman/active_record/association.rb', line 23 def creation_attributes attributes = super # translate keys if reflection.macro.in?([:has_one, :has_many]) && ![:through] attributes[reflection.foreign_key] = Shard.relative_id_for(owner[reflection.active_record_primary_key], owner.shard, self.shard) end attributes end |
#load_target ⇒ Object
14 15 16 |
# File 'lib/switchman/active_record/association.rb', line 14 def load_target self.shard.activate { super } end |
#scope ⇒ Object
18 19 20 21 |
# File 'lib/switchman/active_record/association.rb', line 18 def scope shard_value = @reflection.[:multishard] ? @owner : self.shard @owner.shard.activate { super.shard(shard_value, :association) } end |
#shard ⇒ Object
6 7 8 |
# File 'lib/switchman/active_record/association.rb', line 6 def shard reflection.shard(owner) end |