Sha256: 587673fcdb1cf76b217036ce8e3a4e770a7336edafd9aa65ac95ab2be435899f
Contents?: true
Size: 992 Bytes
Versions: 24
Compression:
Stored size: 992 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: module Atomic #:nodoc: # This class provides the ability to perform an explicit $addToSet # modification on a specific field. class AddToSet include Operation # Sends the atomic $addToSet operation to the database. # # @example Persist the new values. # addToSet.persist # # @return [ Object ] The new array value. # # @since 2.0.0 def persist prepare do document[field] = [] unless document[field] values = document.send(field) values.push(value) unless values.include?(value) values.tap do if document.persisted? collection.update(document.atomic_selector, operation("$addToSet"), options) document.remove_change(field) end end end end end end end end
Version data entries
24 entries across 24 versions & 2 rubygems