I have 2 associated entities like this:
class Solicitation {
<some fields>
/**
* @var \User
*
* @ORM\ManyToOne(targetEntity="User", fetch="EAGER", inversedBy="solicitation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_user", referencedColumnName="id_user", nullable=false)
* })
* @OrderBy({"nome" = "ASC"})
*/
private $user;
<more fields>
}
I don't want to cascade operations. The problem is when I try to merge an existing User before persisting Solicitation, like this:
$em = $this->getDoctrine()->getManager();
if (!(\Doctrine\ORM\UnitOfWork::STATE_MANAGED === $em->getUnitOfWork()->getEntityState($solicitation->getUser()))) {
$em->merge($solicitation->getUser());
}
$em->persist($solicitation);
...it won't change User UnitOfWork state to "MANAGED". I`ts still "DETACHED" and I receive and error on saving.