Class: Mongoid::Associations::AssociationFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/associations/association_factory.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.create(association_type, association_name, document) ⇒ Object

Creates a new association, based on the type provided and passes the name and document into the newly instantiated association.

If the type is invalid a InvalidAssociationError will be thrown.



10
11
12
13
14
15
16
17
# File 'lib/mongoid/associations/association_factory.rb', line 10

def self.create(association_type, association_name, document)
  case association_type
    when :belongs_to then BelongsToAssociation.new(document)
    when :has_many then HasManyAssociation.new(association_name, document)
    when :has_one then HasOneAssociation.new(association_name, document)
    else raise InvalidAssociationError
  end
end