class Mongoid::Association::Embedded::EmbeddedIn

The EmbeddedIn type association.

Constants

ASSOCIATION_OPTIONS

The options available for this type of association, in addition to the common ones.

@return [ Array<Symbol> ] The extra valid options.

VALID_OPTIONS

The complete list of valid options for this association, including the shared ones.

@return [ Array<Symbol> ] The valid options.

Public Instance Methods

embedded?() click to toggle source

Is this association type embedded?

@return [ true ] Always true.

# File lib/mongoid/association/embedded/embedded_in.rb, line 47
def embedded?; true; end
key() click to toggle source

The key that is used to get the attributes for the associated object.

@return [ String ] The name of the association.

# File lib/mongoid/association/embedded/embedded_in.rb, line 67
def key
  @key ||= name.to_s
end
nested_builder(attributes, options) click to toggle source

The nested builder object.

@param [ Hash ] attributes The attributes to use to build the association object. @param [ Hash ] options The options for the association.

@return [ Association::Nested::One ] The Nested Builder object.

# File lib/mongoid/association/embedded/embedded_in.rb, line 91
def nested_builder(attributes, options)
  Nested::One.new(self, attributes, options)
end
polymorphic?() click to toggle source

Is this association polymorphic?

@return [ true | false ] Whether this association is polymorphic.

# File lib/mongoid/association/embedded/embedded_in.rb, line 81
def polymorphic?
  !!@options[:polymorphic]
end
primary_key() click to toggle source

The primary key

@return [ nil ] Not relevant for this association

# File lib/mongoid/association/embedded/embedded_in.rb, line 52
def primary_key; end
relation() click to toggle source

Get the association proxy class for this association type.

@return [ Association::Embedded::EmbeddedIn::Proxy ] The proxy class.

# File lib/mongoid/association/embedded/embedded_in.rb, line 74
def relation
  Proxy
end
setup!() click to toggle source

Setup the instance methods, fields, etc. on the association owning class.

@return [ self ]

# File lib/mongoid/association/embedded/embedded_in.rb, line 37
def setup!
  setup_defaults!
  setup_instance_methods!
  @owner_class.embedded = true
  self
end
stores_foreign_key?() click to toggle source

Does this association type store the foreign key?

@return [ false ] Always false.

# File lib/mongoid/association/embedded/embedded_in.rb, line 57
def stores_foreign_key?; false; end
validation_default() click to toggle source

The default for validating the association object.

@return [ false ] Always false.

# File lib/mongoid/association/embedded/embedded_in.rb, line 62
def validation_default; false; end

Private Instance Methods

determine_inverses(other) click to toggle source
# File lib/mongoid/association/embedded/embedded_in.rb, line 129
def determine_inverses(other)
  matches = (other || relation_class).relations.values.select do |rel|
    relation_complements.include?(rel.class) &&
        rel.relation_class_name == inverse_class_name
  end
  if matches.size > 1
    raise Errors::AmbiguousRelationship.new(relation_class, @owner_class, name, matches)
  end
  matches.collect { |m| m.name } unless matches.blank?
end
polymorphic_inverses(other = nil) click to toggle source
# File lib/mongoid/association/embedded/embedded_in.rb, line 117
def polymorphic_inverses(other = nil)
  if other
    matches = other.relations.values.select do |rel|
      relation_complements.include?(rel.class) &&
          rel.as == name &&
          rel.relation_class_name == inverse_class_name
    end

    matches.map { |m| m.name }
  end
end
relation_complements() click to toggle source
# File lib/mongoid/association/embedded/embedded_in.rb, line 112
def relation_complements
  @relation_complements ||= [ Embedded::EmbedsMany,
                              Embedded::EmbedsOne ].freeze
end
setup_defaults!() click to toggle source

Set up default values for any options used by this association.

# File lib/mongoid/association/embedded/embedded_in.rb, line 98
def setup_defaults!
  @options[:touch] = true unless @options.key?(:touch)
end
setup_instance_methods!() click to toggle source
# File lib/mongoid/association/embedded/embedded_in.rb, line 102
def setup_instance_methods!
  define_getter!
  define_setter!
  define_existence_check!
  define_builder!
  define_creator!
  define_counter_cache_callbacks!
  define_touchable!
end