Module: Switchman::ActiveRecord::AutosaveAssociation
- Defined in:
- lib/switchman/active_record/association.rb
Instance Method Summary collapse
- #record_changed?(reflection, record, key) ⇒ Boolean
- #save_belongs_to_association(reflection) ⇒ Object
Instance Method Details
#record_changed?(reflection, record, key) ⇒ Boolean
192 193 194 195 196 |
# File 'lib/switchman/active_record/association.rb', line 192 def record_changed?(reflection, record, key) record.new_record? || (record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key) || # have to use send instead of [] because sharding record.attribute_changed?(reflection.foreign_key) end |
#save_belongs_to_association(reflection) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/switchman/active_record/association.rb', line 198 def save_belongs_to_association(reflection) # this seems counter-intuitive, but the autosave code will assign to attribute bypassing switchman, # after reading the id attribute _without_ bypassing switchman. So we need Shard.current for the # category of the associated record to match Shard.current for the category of self shard.activate(connection_classes_for_reflection(reflection)) { super } end |