Module: Mongoid::Relations::AutoSave

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Relations
Defined in:
lib/mongoid/relations/auto_save.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) __autosaving__

Begin the associated autosave.

Examples:

Begin autosave.

document.__autosaving__

Since:

  • 3.1.3



28
29
30
31
32
33
# File 'lib/mongoid/relations/auto_save.rb', line 28

def __autosaving__
  Threaded.begin_autosave(self)
  yield
ensure
  Threaded.exit_autosave(self)
end

- (true, false) autosaved?

Used to prevent infinite loops in associated autosaves.

Examples:

Is the document autosaved?

document.autosaved?

Since:

  • 3.0.0



18
19
20
# File 'lib/mongoid/relations/auto_save.rb', line 18

def autosaved?
  Threaded.autosaved?(self)
end

- (Boolean) changed_for_autosave?(doc)

Check if there is changes for auto-saving

document.changed_for_autosave?

Examples:

Return true if there is changes on self or in

autosaved relations.

Since:

  • 3.1.3



42
43
44
# File 'lib/mongoid/relations/auto_save.rb', line 42

def changed_for_autosave?(doc)
  doc.new_record? || doc.changed? || doc.marked_for_destruction?
end