Why is the record removed when the Owner has been changed?

Asked

Viewed 12 times

1

I created a method to alter the Owner of the records.

$sql = "UPDATE Contato\Entity\Email t SET t.$column = :contato1 WHERE t.$column = :contato2";
$query = $this->getEntityManager()->createQuery($sql);
$query->setParameters(array(
    'contato1' => $contato1,
    'contato2' => $contato2
));
$query->execute();

After the query records are physically updated in the database. But when the command to delete the old Owner is executed, records that have been updated are also deleted which in this case exemplified, emails are deleted.

$this->getEntityManager()->remove($contato2);

What do I need to do to rule out $contato2 without removing your old relationships that were meant for another contact?

  • You could save the old query, or in case the old information in a var, create a query with this inf. after this deletes the old information and adds the new, if this does not return any error you delete the variable you saved.... This is what I understand about your problem, or I could be very wrong.

  • Not that not kkk I will update the question with a logical example.

  • ok, will facilitate kkkk

  • Are the two commands executed in the same process or in different processes? It may be that Doctrine is caching relations even after flush the changes.

  • In separate cases. First I perform 7 functions that perform the update similarly to the explained and at the end of every operation I run the remove(); I put a flush() before the remove() for consciousness-raising but did not resolve :'(.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.