module Mongoid::Relations::AutoSave

This module contains the behaviour for auto-saving relations in different collections.

Public Instance Methods

__autosaving__() { || ... } click to toggle source

Begin the associated autosave.

@example Begin autosave.

document.__autosaving__

@since 3.1.3

# File lib/mongoid/relations/auto_save.rb, line 28
def __autosaving__
  Threaded.begin_autosave(self)
  yield
ensure
  Threaded.exit_autosave(self)
end
autosaved?() click to toggle source

Used to prevent infinite loops in associated autosaves.

@example Is the document autosaved?

document.autosaved?

@return [ true, false ] Has the document already been autosaved?

@since 3.0.0

# File lib/mongoid/relations/auto_save.rb, line 18
def autosaved?
  Threaded.autosaved?(self)
end
changed_for_autosave?(doc) click to toggle source

Check if there is changes for auto-saving

@example Return true if there is changes on self or in

        autosaved relations.
document.changed_for_autosave?

@since 3.1.3

# File lib/mongoid/relations/auto_save.rb, line 42
def changed_for_autosave?(doc)
  doc.new_record? || doc.changed? || doc.marked_for_destruction?
end