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 33 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 23 def autosaved? Threaded.autosaved?(self) end
changed_for_autosave?()
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 47 def changed_for_autosave? new_record? || changed? || marked_for_destruction? end
relation_changed_for_autosave(metadata)
click to toggle source
Returns the relation, if it exists
@since 3.1.3
# File lib/mongoid/relations/auto_save.rb, line 54 def relation_changed_for_autosave(metadata) ivar(metadata.name) if self.class.autosaved_relations.include?(metadata.name) end