0
votes

I have a little problem with Doctrine 2 ... I am trying to update an Entity in my Database but instead of just updating it, it also inserts another Entity... Furthermore if i dont even flush and rather just find the Entity of interest and set the values it also just adds another record in the database why is that?

Variant 1 (inserting a new record only)

$state = $this->getObjectManager()->find('Application\Entity\ProjectPhase\State', $pps_exists['stateId']);
$state->setValue($phaseData['value']);
$state->setCreatedat(new \DateTime($phaseData['date']));

As you can see i dont even use flush/merge/persist ... it still just inserts a record.

public function getObjectManager() { 
        $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
}

On the other Hand if i add and call $this->getObjectManager()->flush(); It actually updates the record after an unnecessary record has already been added to the db... makes no sense... I also tried it with DQL-Update ... Same behaviour as setValue + flush() .... Thanks in advance!

1

1 Answers

0
votes

Nevermind i nested these statements inside two if blocks one for "create" and one for "update" ... Stupid mistake writing if($action = 'create') instead of if($action == 'create') ... this post is closed as a so called "Layer 8"-issue :) thanks anyways