Module: Switchman::ActiveRecord::Association
- Defined in:
- lib/switchman/active_record/association.rb
Instance Method Summary collapse
- #association_scope ⇒ Object
- #build_record(*args) ⇒ Object
- #creation_attributes ⇒ Object
- #load_target ⇒ Object
- #scope ⇒ Object
- #shard ⇒ Object
Instance Method Details
#association_scope ⇒ Object
16 17 18 19 20 |
# File 'lib/switchman/active_record/association.rb', line 16 def association_scope if klass shard.activate(klass.shard_category) { super } end end |
#build_record(*args) ⇒ Object
8 9 10 |
# File 'lib/switchman/active_record/association.rb', line 8 def build_record(*args) self.shard.activate { super } end |
#creation_attributes ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/switchman/active_record/association.rb', line 27 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
12 13 14 |
# File 'lib/switchman/active_record/association.rb', line 12 def load_target self.shard.activate { super } end |
#scope ⇒ Object
22 23 24 25 |
# File 'lib/switchman/active_record/association.rb', line 22 def scope shard_value = @reflection.[:multishard] ? @owner : self.shard @owner.shard.activate { super.shard(shard_value, :association) } end |
#shard ⇒ Object
4 5 6 |
# File 'lib/switchman/active_record/association.rb', line 4 def shard reflection.shard(owner) end |