lib/mongoid/relations/auto_save.rb
# Set up the autosave behaviour for references many and references one
# relations. When the option is set to true, these relations will get
# saved automatically when the parent saved, if they are dirty.
#
# @example Set up autosave options.
#   Person.autosave(metadata)
#
# @param [ Metadata ] metadata The relation metadata.
#
# @since 2.0.0.rc.1
Set up the autosave behaviour for references many and references one
relations. When the option is set to true, these relations will get
saved automatically when the parent saved, if they are dirty.
Set up the autosave behaviour for references many and references one relations . When the option is set to true these relations will get saved automatically when the parent saved if they are dirty .
def autosave(metadata)
          if metadata.autosave? && autosavable?(metadata)
            autosaved_relations.push(metadata.name)
            set_callback :save, :after, unless: :autosaved? do |document|
              if before_callback_halted?
                self.before_callback_halted = false
              else
                __autosaving__ do
                  if document.changed_for_autosave? || relation = document.relation_changed_for_autosave(metadata)
                    relation = document.__send__(metadata.name) unless relation
                    (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc|
                      doc.save
                    end if relation
                  end
                end
              end
            end
          end
        end
def autosave ( metadata ) if metadata . autosave? && autosavable? ( metadata ) autosaved_relations . push ( metadata . name ) set_callback :save , :after , unless : :autosaved? do | document | if before_callback_halted? self . before_callback_halted = false else __autosaving__ do if document . changed_for_autosave? || relation = document . relation_changed_for_autosave ( metadata ) relation = document . __send__ ( metadata . name ) unless relation ( relation . do_or_do_not ( :in_memory ) || Array . wrap ( relation ) ) . each do | doc | doc . save end if relation end end end end end end
Set up the autosave behaviour for references many and references one
relations.
Set up the autosave behaviour for references many and references one relations .
metadata
metadata The relation metadata.
metadata The relation metadata .
example
Set up autosave options. Person.autosave(metadata)
Set up autosave options . Person . autosave ( metadata )
since
None