utilities/handler-helper.js
async function _removeOneHandler(
  ownerModel,
  ownerId,
  childModel,
  childId,
  associationName,
  request,
  Log
) {
  try {
    let ownerObject = await ownerModel
      .findOne({ _id: ownerId })
      .select(associationName)
    if (ownerObject) {
      try {
        if (
          ownerModel.routeOptions &&
          ownerModel.routeOptions.remove &&
          ownerModel.routeOptions.remove[associationName] &&
          ownerModel.routeOptions.remove[associationName].pre
        ) {
          await ownerModel.routeOptions.remove[associationName].pre(
            {},
            request,
            Log
          )
        }
      } catch (err) {
        handleError(
          err,
          'There was a preprocessing error while removing the association.',
          Boom.badRequest,
          Log
        )
      }

      try {
        await _removeAssociation(
          ownerModel,
          ownerObject,
          childModel,
          childId,
          associationName,
          Log
        )
      } catch (err) {
        handleError(
          err,
          'There was a database error while removing the association.',
          Boom.badImplementation,
          Log
        )
      }
      return true
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _removeOneHandler(
  ownerModel,
  ownerId,
  childModel,
  childId,
  associationName,
  request,
  Log
) {
  try {
    let ownerObject = await ownerModel
      .findOne({ _id: ownerId })
      .select(associationName)
    if (ownerObject) {
      try {
        if (
          ownerModel.routeOptions &&
          ownerModel.routeOptions.remove &&
          ownerModel.routeOptions.remove[associationName] &&
          ownerModel.routeOptions.remove[associationName].pre
        ) {
          await ownerModel.routeOptions.remove[associationName].pre(
            {},
            request,
            Log
          )
        }
      } catch (err) {
        handleError(
          err,
          'There was a preprocessing error while removing the association.',
          Boom.badRequest,
          Log
        )
      }

      try {
        await _removeAssociation(
          ownerModel,
          ownerObject,
          childModel,
          childId,
          associationName,
          Log
        )
      } catch (err) {
        handleError(
          err,
          'There was a database error while removing the association.',
          Boom.badImplementation,
          Log
        )
      }
      return true
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
async function _removeOneHandler ( ownerModel , ownerId , childModel , childId , associationName , request , Log ) { try { let ownerObject = await ownerModel . findOne ( { _id : ownerId } ) . select ( associationName ) if ( ownerObject ) { try { if ( ownerModel . routeOptions && ownerModel . routeOptions . remove && ownerModel . routeOptions . remove [ associationName ] && ownerModel . routeOptions . remove [ associationName ] . pre ) { await ownerModel . routeOptions . remove [ associationName ] . pre ( { } , request , Log ) } } catch ( err ) { handleError ( err , 'There was a preprocessing error while removing the association.' , Boom . badRequest , Log ) } try { await _removeAssociation ( ownerModel , ownerObject , childModel , childId , associationName , Log ) } catch ( err ) { handleError ( err , 'There was a database error while removing the association.' , Boom . badImplementation , Log ) } return true } else { throw Boom . notFound ( 'No resource was found with that id.' ) } } catch ( err ) { handleError ( err , null , null , Log ) } }
Removes an association to a document
@param ownerModel: The model that is being removed from.
@param ownerId: The id of the owner document.
@param childModel: The model that is being removed.
@param childId: The id of the child document.
@param associationName: The name of the association from the ownerModel's perspective.
@param request: The Hapi request object.
@param Log: A logging object
@returns {object} A promise returning true if the remove succeeds.
@private
Removes an association to a document