Sha256: dc1ac5fb42006537c82394bc9e1521d8011b7ccc790ca75bbb2ff2538a83d70e

Contents?: true

Size: 1.56 KB

Versions: 65

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:
    module Bindings #:nodoc:
      module Referenced #:nodoc:

        # Binding class for references_many relations.
        class Many < Binding

          # Binds a single document with the inverse relation. Used
          # specifically when appending to the proxy.
          #
          # @example Bind one document.
          #   person.posts.bind_one(post)
          #
          # @param [ Document ] doc The single document to bind.
          #
          # @since 2.0.0.rc.1
          def bind_one(doc)
            unless _binding?
              _binding do
                doc.you_must(metadata.foreign_key_setter, base.id)
                if metadata.type
                  doc.you_must(metadata.type_setter, base.class.model_name)
                end
                doc.send(metadata.inverse_setter, base)
              end
            end
          end

          # Unbind a single document.
          #
          # @example Unbind the document.
          #   person.posts.unbind_one(document)
          #
          # @param [ Document ] document The document to unbind.
          #
          # @since 2.0.0.rc.1
          def unbind_one(doc)
            unless _binding?
              _binding do
                doc.you_must(metadata.foreign_key_setter, nil)
                if metadata.type
                  doc.you_must(metadata.type_setter, nil)
                end
                doc.send(metadata.inverse_setter, nil)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.8 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.7 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.6 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.5.15 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.5.14 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many.rb