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

#__autosaving__Object

Begin the associated autosave.

Examples:

Begin autosave.

document.__autosaving__

Since:

  • 3.1.3



33
34
35
36
37
38
# File 'lib/mongoid/relations/auto_save.rb', line 33

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

#autosaved?true, false

Used to prevent infinite loops in associated autosaves.

Examples:

Is the document autosaved?

document.autosaved?

Returns:

  • (true, false)

    Has the document already been autosaved?

Since:

  • 3.0.0



23
24
25
# File 'lib/mongoid/relations/auto_save.rb', line 23

def autosaved?
  Threaded.autosaved?(self)
end

#changed_for_autosave?Boolean

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.

Returns:

Since:

  • 3.1.3



47
48
49
# File 'lib/mongoid/relations/auto_save.rb', line 47

def changed_for_autosave?
  new_record? || changed? || marked_for_destruction?
end

#relation_changed_for_autosave(metadata) ⇒ Object

Returns the relation, if it exists

Since:

  • 3.1.3



54
55
56
# File 'lib/mongoid/relations/auto_save.rb', line 54

def relation_changed_for_autosave()
  ivar(.name) if self.class.autosaved_relations.include?(.name)
end