class Mongoid::Association::Embedded::EmbeddedIn::Binding

The Binding object for embedded_in associations.

def bind_one

Other tags:
    Example: Bind the documents. -
def bind_one
  binding do
    check_polymorphic_inverses!(_target)
    _base._association = _association.inverse_association(_target) unless _base._association
    _base.parentize(_target)
    if _base.embedded_many?
      _target.do_or_do_not(_association.inverse(_target)).push(_base)
    else
      remove_associated(_target)
      _target.do_or_do_not(_association.inverse_setter(_target), _base)
    end
  end
end

def check_polymorphic_inverses!(doc)

Parameters:
  • doc (Document) -- The document to check.

Other tags:
    Example: Check for inverses errors. -

Other tags:
    Api: - private
def check_polymorphic_inverses!(doc)
  if inverses = _association.inverses(doc)
    if inverses.length > 1
      raise Errors::InvalidSetPolymorphicRelation.new(
          _association.name, _base.class.name, _target.class.name
      )
    end
  end
end

def unbind_one

Other tags:
    Example: Unbind the document. -
def unbind_one
  binding do
    if _base.embedded_many?
      _target.do_or_do_not(_association.inverse(_target)).delete(_base)
    else
      _target.do_or_do_not(_association.inverse_setter(_target), nil)
    end
  end
end