Sha256: 7bc1f1e986e9dc9ba0319d90fd5e88742a59cd5586a0c23efe90b788ab3fa307

Contents?: true

Size: 760 Bytes

Versions: 11

Compression:

Stored size: 760 Bytes

Contents

module Mongoid #:nodoc:
  module Associations #:nodoc:
    class Factory #:nodoc:

      # 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.
      def self.create(association_type, association_name, document, options = {})
        case association_type
          when :belongs_to then BelongsToAssociation.new(document)
          when :has_many then HasManyAssociation.new(association_name, document, options)
          when :has_one then HasOneAssociation.new(association_name, document, options)
          else raise InvalidAssociationError
        end
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mongoid-0.6.3 lib/mongoid/associations/factory.rb
mongoid-0.6.2 lib/mongoid/associations/factory.rb
mongoid-0.6.1 lib/mongoid/associations/factory.rb
mongoid-0.6.0 lib/mongoid/associations/factory.rb
mongoid-0.5.11 lib/mongoid/associations/factory.rb
mongoid-0.5.10 lib/mongoid/associations/factory.rb
mongoid-0.5.9 lib/mongoid/associations/factory.rb
mongoid-0.5.8 lib/mongoid/associations/factory.rb
mongoid-0.5.7 lib/mongoid/associations/factory.rb
mongoid-0.5.6 lib/mongoid/associations/factory.rb
mongoid-0.5.5 lib/mongoid/associations/factory.rb