Class: Mongoid::Relations::Builders::Referenced::ManyToMany

Inherits:
Mongoid::Relations::Builder show all
Defined in:
lib/mongoid/relations/builders/referenced/many_to_many.rb

Overview

Since:

Instance Attribute Summary

Attributes inherited from Mongoid::Relations::Builder

#base, #metadata, #object

Instance Method Summary (collapse)

Methods inherited from Mongoid::Relations::Builder

#initialize

Constructor Details

This class inherits a constructor from Mongoid::Relations::Builder

Instance Method Details

- (Array<Document>) build(type = nil)

This builder either takes a hash and queries for the object or an array of documents, where it will just return them.

Examples:

Build the documents.

Builder.new(meta, attrs).build

Since:

  • 2.0.0.rc.1



17
18
19
20
21
# File 'lib/mongoid/relations/builders/referenced/many_to_many.rb', line 17

def build(type = nil)
  return object.try(:dup) unless query?
  ids = object || []
  .criteria(ids, base.class)
end

- (true, false) query?

Do we need to perform a database query? It will be so if the object we have is not a document.

Examples:

Should we query the database?

builder.query?

Since:

  • 2.0.0.rc.1



32
33
34
# File 'lib/mongoid/relations/builders/referenced/many_to_many.rb', line 32

def query?
  object.nil? || !object.first.is_a?(Mongoid::Document)
end