Module: Switchman::ActiveRecord::Associations::AutosaveAssociation
- Defined in:
- lib/switchman/active_record/associations.rb
Instance Method Summary collapse
- #association_foreign_key_changed?(reflection, record, key) ⇒ Boolean
- #save_belongs_to_association(reflection) ⇒ Object
Instance Method Details
#association_foreign_key_changed?(reflection, record, key) ⇒ Boolean
295 296 297 298 299 300 |
# File 'lib/switchman/active_record/associations.rb', line 295 def association_foreign_key_changed?(reflection, record, key) return false if reflection.through_reflection? # have to use send instead of _read_attribute because sharding record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key end |
#save_belongs_to_association(reflection) ⇒ Object
302 303 304 305 306 307 |
# File 'lib/switchman/active_record/associations.rb', line 302 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_class_for_self_for_reflection(reflection)) { super } end |