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
203 204 205 206 207 |
# File 'lib/switchman/active_record/association.rb', line 203 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
209 210 211 212 213 214 |
# File 'lib/switchman/active_record/association.rb', line 209 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(shard_category_for_reflection(reflection)) { super } end |