Sha256: 91e63fc2ab7b7b27a4e5c00feeabdf0f1ecd47a6d1f0e5931d9382a483eaefa5
Contents?: true
Size: 1.3 KB
Versions: 9
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true module Mongoid module Persistable # Defines behavior for persistence operations that save documents. module Savable # Save the document - will perform an insert if the document is new, and # update if not. # # @example Save the document. # document.save # # @param [ Hash ] options Options to pass to the save. # # @return [ true, false ] True is success, false if not. def save(options = {}) if new_record? !insert(options).new_record? else update_document(options) end end # Save the document - will perform an insert if the document is new, and # update if not. If a validation error occurs an error will get raised. # # @example Save the document. # document.save! # # @param [ Hash ] options Options to pass to the save. # # @raise [ Errors::Validations ] If validation failed. # @raise [ Errors::Callback ] If a callback returns false. # # @return [ true, false ] True if validation passed. def save!(options = {}) unless save(options) fail_due_to_validation! unless errors.empty? fail_due_to_callback!(:save!) end true end end end end
Version data entries
9 entries across 9 versions & 1 rubygems