class Mongoid::Association::Referenced::HasOne

The has_one association.

def bindable?(doc)

Returns:
  • (true | false) - Whether the document can be bound.

Parameters:
  • doc (Document) -- The document to be bound.
def bindable?(doc)
  forced_nil_inverse? || (!!inverse && doc.fields.keys.include?(foreign_key))
end

def default_foreign_key_field

def default_foreign_key_field
  @default_foreign_key_field ||= "#{inverse}#{FOREIGN_KEY_SUFFIX}"
end

def default_primary_key

def default_primary_key
  PRIMARY_KEY_DEFAULT
end

def determine_inverses(other)

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

def embedded?; false; end

Returns:
  • (false) - Always false.
def embedded?; false; end

def foreign_key

Returns:
  • (String) - The foreign key field for saving the
def foreign_key
  @foreign_key ||= @options[:foreign_key] ? @options[:foreign_key].to_s :
                     default_foreign_key_field
end

def nested_builder(attributes, options)

Returns:
  • (Association::Nested::Many) - The Nested Builder object.

Parameters:
  • options (Hash) -- The options for the association.
  • attributes (Hash) -- The attributes to use to build the association object.
def nested_builder(attributes, options)
  Nested::One.new(self, attributes, options)
end

def path(document)

Returns:
  • (Root) - The root atomic path calculator.

Parameters:
  • document (Document) -- The document to calculate on.

Other tags:
    Example: Get the path calculator. -
def path(document)
  Mongoid::Atomic::Paths::Root.new(document)
end

def polymorphic?

Returns:
  • (true | false) - Whether this association is polymorphic.
def polymorphic?
  @polymorphic ||= !!as
end

def polymorphic_inverses(other)

def polymorphic_inverses(other)
  [ as ]
end

def relation

Returns:
  • (Association::HasOne::Proxy) - The proxy class.
def relation
  Proxy
end

def relation_complements

Returns:
  • (Array) - The association complements.
def relation_complements
  @relation_complements ||= [ Referenced::BelongsTo ].freeze
end

def scope

Returns:
  • (Proc | Symbol | nil) - The association scope, if any.
def scope
  @options[:scope]
end

def setup!

Returns:
  • (self) -
def setup!
  setup_instance_methods!
  self
end

def setup_instance_methods!

Returns:
  • (self) -
def setup_instance_methods!
  define_getter!
  define_setter!
  define_existence_check!
  define_builder!
  define_creator!
  define_autosaver!
  polymorph!
  define_dependency!
  @owner_class.validates_associated(name) if validate?
  self
end

def stores_foreign_key?; false; end

def stores_foreign_key?; false; end

def type

Returns:
  • (String | nil) - The type field.

Other tags:
    Note: - Only relevant for polymorphic associations.
def type
  @type ||= "#{as}_type" if polymorphic?
end

def validation_default; true; end

Returns:
  • (true) - Always true.
def validation_default; true; end