/**
     * @param \SchemaPropertyElement | \SchemaPropertyElement[] $dbElement
     * @param \SchemaProperty                                   $property
     *
     * @return int
     */
    private function deleteElement(&$dbElement, &$property)
    {
        if ( ! is_array($dbElement)) {
            //we don't delete derived properties at this stage
//      if (in_array($dbElement->getProfilePropertyId(),[6,9]))
//      {
//        return 0;
//      }
            $profileProperty = $this->profileProperties[$dbElement->getProfilePropertyId()];
            if ($profileProperty->getIsInForm() and $property->getLanguage() == $dbElement->getLanguage()) {
                $this->setPropertyValue('',
                                        $property,
                                        $profileProperty->getName(), ! $profileProperty->getIsObjectProp());
            }
            $dbElement->setUpdatedUserId($this->userId);
            $dbElement->importId = $this->importId;

            //$affectedRows = $dbElement->save();
            return $dbElement->delete();
        } else {
            $affectedRows = 0;
            /** @var \SchemaPropertyElement $element */
            foreach ($dbElement as &$element) {
                $affectedRows += $this->deleteElement($element, $property);
            }

            return $affectedRows;
        }
    }
 /**
  * @param SchemaProperty $property
  * @param string                            $fieldName
  * @param string                            $object
  * @param int                               $objectId if the object has a related Id
  * @param int                               $userId
  * @param array                             $fieldIds
  * @param int                               $statusId
  * @param Connection                        $con
  *
  * @throws Exception
  * @throws PropelException
  * @return bool
  */
 public static function updateRelatedElements($property, $fieldName, $object, $objectId, $userId, $fieldIds, $statusId, $con)
 {
     if (isset($fieldIds[$fieldName])) {
         $profileId = $fieldIds[$fieldName]['id'];
     } else {
         return false;
     }
     $language = $fieldIds[$fieldName]['hasLang'] ? $property->getLanguage() : null;
     $element = SchemaPropertyElementPeer::lookupDetailElement($property->getId(), $profileId, $language);
     if ($element) {
         //no matter what we do, it's not generated any more
         $element->setIsGenerated(false);
         //did we make it null?
         if (0 === strlen(trim($object))) {
             //we have to make sure that it's not a subclass or subproperty
             if (('is_subproperty_of' == $fieldName || 'is_subclass_of' == $fieldName) && $property->getParentUri()) {
                 //there's a uri but it doesn't match anything registered
                 //so we have to delete just the reciprocal
                 $element->updateReciprocal('deleted', $userId, $property->getSchemaId(), $con);
             } else {
                 //delete the element
                 $element->delete($con);
             }
         } else {
             //modify it
             $element->setObject($object);
             $element->setRelatedSchemaPropertyId($objectId);
             $element->setUpdatedUserId($userId);
             $element->save();
         }
     } elseif ($profileId && $object) {
         //create one
         $element = SchemaPropertyElementPeer::createElement($property, $userId, $profileId, $statusId, $language, false);
         $element->setObject($object);
         $element->setRelatedSchemaPropertyId($objectId);
         $element->setIsSchemaProperty(TRUE);
         $element->save();
     }
     return true;
 }