2
votes

Description: I have an User entity, which has a Profile entity.

Problem:

  • I load User from database, and change only some property in it's Profile.
  • I call:

    $entityManager->flush($user);

  • But the User doesn't have any property changed, only it's Profile is changed.

  • I have set the cascade={"persist"} on the profile property inside user object.

Everything works if I call:

  • $entityManager->flush();

Note: Without the object itself. I do not really want to do it without an object as argument, since I might flush some other changes in other entities, which I am not aware of at that particular moment. Looks like when someone calls the flush method with an object as argument, it is not aware of cascading the persistence. Any ideas how to solve this?

1
Why not $entityManager->flush($profile); ?Hpatoio
Yes, flushing profile works as well, could be a solution, but I thought that flushing user would be a nicer solution.tomazahlin
Why ? You are modifying the profile, not the user. That's the correct behaviour.Hpatoio
I thought because of the cascade={"persist"}, it should also flush the changes for profile. Good, I will make the solution like you suggest, I like it anyway. :)tomazahlin
Doctrine doesn't see any change in the $user so it doesn't perform any action on persist.Hpatoio

1 Answers

5
votes

Due you are modifying the profile and not the user you should use:

$entityManager->flush($profile);