Sha256: 626b7c7c96e3517a242d745e1606ce9de25150465f97b4ea59ed96bef6e87c2d

Contents?: true

Size: 1.63 KB

Versions: 169

Compression:

Stored size: 1.63 KB

Contents

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

        # Binding class for all references_and_referenced_in_many relations.
        class ManyToMany < Binding

          # Binds a single document with the inverse relation. Used
          # specifically when appending to the proxy.
          #
          # @example Bind one document.
          #   person.preferences.bind_one(preference)
          #
          # @param [ Document ] doc The single document to bind.
          #
          # @since 2.0.0.rc.1
          def bind_one(doc)
            unless _binding?
              _binding do
                inverse_keys = doc.you_must(metadata.inverse_foreign_key)
                inverse_keys.push(base.id) if inverse_keys
                base.synced[metadata.foreign_key] = true
                doc.synced[metadata.inverse_foreign_key] = true
              end
            end
          end

          # Unbind a single document.
          #
          # @example Unbind the document.
          #   person.preferences.unbind_one(document)
          #
          # @since 2.0.0.rc.1
          def unbind_one(doc)
            unless _binding?
              _binding do
                base.send(metadata.foreign_key).delete_one(doc.id)
                inverse_keys = doc.you_must(metadata.inverse_foreign_key)
                inverse_keys.delete_one(base.id) if inverse_keys
                base.synced[metadata.foreign_key] = true
                doc.synced[metadata.inverse_foreign_key] = true
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

169 entries across 77 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.5 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
mongoid-2.8.1 lib/mongoid/relations/bindings/referenced/many_to_many.rb
mongoid-2.8.0 lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/relations/bindings/referenced/many_to_many.rb
classiccms-0.7.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/relations/bindings/referenced/many_to_many.rb