Sha256: 78e2a70ac063b311a898143e6a7a90a723905e10abc8565e42dd8deece7c8c1a

Contents?: true

Size: 1.15 KB

Versions: 164

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:
    module Builders #:nodoc:
      module Referenced #:nodoc:
        class ManyToMany < Builder

          # This builder either takes a hash and queries for the
          # object or an array of documents, where it will just return them.
          #
          # @example Build the documents.
          #   Builder.new(meta, attrs).build
          #
          # @param [ String ] type The type of document to query for.
          #
          # @return [ Array<Document> ] The documents.
          def build(type = nil)
            return object.try(:dup) unless query?
            metadata.criteria(object || [])
          end

          # Do we need to perform a database query? It will be so if the object we
          # have is not a document.
          #
          # @example Should we query the database?
          #   builder.query?
          #
          # @return [ true, false ] Whether a database query should happen.
          #
          # @since 2.0.0.rc.1
          def query?
            object.nil? || !object.first.is_a?(Mongoid::Document)
          end
        end
      end
    end
  end
end

Version data entries

164 entries across 72 versions & 3 rubygems

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