module Switchman::ActiveRecord::AutosaveAssociation
Public Instance Methods
record_changed?(reflection, record, key)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# 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