Sha256: 0a518ca3810003f8f8492285b7b8dae6d3f3eda3a268e65c3409d0cd10fde5f3

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Mongoid
  module Association
    module Embedded
      class EmbedsMany

        # Binding class for all embeds_many associations.
        class Binding
          include Bindable

          # Binds a single document with the inverse association. Used
          # specifically when appending to the proxy.
          #
          # @example Bind one document.
          #   person.addresses.bind_one(address)
          #
          # @param [ Document ] doc The single document to bind.
          def bind_one(doc)
            doc.parentize(_base)
            binding do
              doc.do_or_do_not(_association.inverse_setter(_target), _base)
            end
          end

          # Unbind a single document.
          #
          # @example Unbind the document.
          #   person.addresses.unbind_one(document)
          #
          # @param [ Document ] doc The single document to unbind.
          def unbind_one(doc)
            binding do
              doc.do_or_do_not(_association.inverse_setter(_target), nil)
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-7.5.4 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.5.3 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.5.2 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.5.1 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.4.3 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.5.0 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.4.1 lib/mongoid/association/embedded/embeds_many/binding.rb
mongoid-7.4.0 lib/mongoid/association/embedded/embeds_many/binding.rb