Can the autosave be added?
@example Can the autosave be added?
Person.autosavable?(metadata)
@param [ Metadata ] metadata The relation metadata.
@return [ true, false ] If the autosave is able to be added.
@since 3.0.0
# File lib/mongoid/relations/auto_save.rb, line 89 def autosavable?(metadata) !autosaved_relations.include?(metadata.name) && !metadata.embedded? end
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
# File lib/mongoid/relations/auto_save.rb, line 58 def autosave(metadata) if metadata.autosave? && autosavable?(metadata) autosaved_relations.push(metadata.name) set_callback :save, :after, unless: :autosaved? do |document| # @todo: Durran: Remove with Rails 4 after callback termination. if before_callback_halted? self.before_callback_halted = false else begin_autosave relation = document.send(metadata.name) if relation (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc| doc.save end end exit_autosave end end end end # Can the autosave be added? # # @example Can the autosave be added? # Person.autosavable?(metadata) # # @param [ Metadata ] metadata The relation metadata. # # @return [ true, false ] If the autosave is able to be added. # # @since 3.0.0 def autosavable?(metadata) !autosaved_relations.include?(metadata.name) && !metadata.embedded? end end
Generated with the Darkfish Rdoc Generator 2.