Sha256: e29b23d083ea4de4b558f02daed91bfc7567491839e024bc2cb0ce5d09fc0828

Contents?: true

Size: 1.53 KB

Versions: 104

Compression:

Stored size: 1.53 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)
            doc.you_must(metadata.foreign_key_setter, base.id)
            if metadata.type
              doc.you_must(metadata.type_setter, base.class.model_name)
            end
            unless _binding?
              _binding do
                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)
            doc.you_must(metadata.foreign_key_setter, nil)
            if metadata.type
              doc.you_must(metadata.type_setter, nil)
            end
            unless _binding?
              _binding do
                doc.send(metadata.inverse_setter, nil)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

104 entries across 58 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.8.1 lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.8.0 lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.7.1 lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.7.0 lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.6.0 lib/mongoid/relations/bindings/referenced/many.rb
mongoid-2.5.2 lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many.rb
classiccms-0.6.9 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many.rb