private function checkBelongsToRelation($entity, $relation)
    {
        $varObjName = $relation->varObjectName();
        $varIdName  = $relation->varIdName();

        $currentRelation  = $this->getValue($entity, $varObjName);
        $originalRelation = $this->getValue($this->entityRegistry->getOriginal($entity), $varObjName);

        if (empty($currentRelation)) {
            // Current entity has no relation
            if (!empty($originalRelation)) {
                // Original had a relation, so relation was removed
                $this->setValue($entity, $varIdName, null);

                if ($relation->isRequired()) {
                    $this->scheduleForDeletion($entity);
                }
            }

            return;
        }

        // Current entity has a relation
        $currentRelationHash = $this->entityRegistry->getObjectHashId($currentRelation);

        if (empty($originalRelation)) {
            // Original had no relation, so relation was newly created
            $this->scheduleRelationForInsertion($currentRelation, $entity, $varIdName);

            return;
        }

        $originalRelationHash = $this->entityRegistry->getObjectHashId($originalRelation);

        if ($currentRelationHash != $originalRelationHash) {
            // Relation was exchanged
            $this->scheduleRelationForInsertion($currentRelation, $entity, $varIdName);
            $this->setValue($entity, $varIdName, null);
        }
    }
private function checkBelongsToRelation($entity, $relation)
    {
        $varObjName = $relation->varObjectName();
        $varIdName  = $relation->varIdName();

        $currentRelation  = $this->getValue($entity, $varObjName);
        $originalRelation = $this->getValue($this->entityRegistry->getOriginal($entity), $varObjName);

        if (empty($currentRelation)) {
            // Current entity has no relation
            if (!empty($originalRelation)) {
                // Original had a relation, so relation was removed
                $this->setValue($entity, $varIdName, null);

                if ($relation->isRequired()) {
                    $this->scheduleForDeletion($entity);
                }
            }

            return;
        }

        // Current entity has a relation
        $currentRelationHash = $this->entityRegistry->getObjectHashId($currentRelation);

        if (empty($originalRelation)) {
            // Original had no relation, so relation was newly created
            $this->scheduleRelationForInsertion($currentRelation, $entity, $varIdName);

            return;
        }

        $originalRelationHash = $this->entityRegistry->getObjectHashId($originalRelation);

        if ($currentRelationHash != $originalRelationHash) {
            // Relation was exchanged
            $this->scheduleRelationForInsertion($currentRelation, $entity, $varIdName);
            $this->setValue($entity, $varIdName, null);
        }
    }
private function checkBelongsToRelation ( $ entity , $ relation ) { $ varObjName = $ relation -> varObjectName ( ) ; $ varIdName = $ relation -> varIdName ( ) ; $ currentRelation = $ this -> getValue ( $ entity , $ varObjName ) ; $ originalRelation = $ this -> getValue ( $ this -> entityRegistry -> getOriginal ( $ entity ) , $ varObjName ) ; if ( empty ( $ currentRelation ) ) { // Current entity has no relation if ( ! empty ( $ originalRelation ) ) { // Original had a relation, so relation was removed $ this -> setValue ( $ entity , $ varIdName , null ) ; if ( $ relation -> isRequired ( ) ) { $ this -> scheduleForDeletion ( $ entity ) ; } } return ; } // Current entity has a relation $ currentRelationHash = $ this -> entityRegistry -> getObjectHashId ( $ currentRelation ) ; if ( empty ( $ originalRelation ) ) { // Original had no relation, so relation was newly created $ this -> scheduleRelationForInsertion ( $ currentRelation , $ entity , $ varIdName ) ; return ; } $ originalRelationHash = $ this -> entityRegistry -> getObjectHashId ( $ originalRelation ) ; if ( $ currentRelationHash != $ originalRelationHash ) { // Relation was exchanged $ this -> scheduleRelationForInsertion ( $ currentRelation , $ entity , $ varIdName ) ; $ this -> setValue ( $ entity , $ varIdName , null ) ; } }
Check for changes in a belongsTo relation

We are handling a Detail and checking the Master.
Detail->masterId = Master->id

@param   object    $entity   The entity
@param   BelongsTo $relation The relation

@return  void
Check for changes in a belongsTo relation