Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When merging a User, you want the associated Company and Privilege to be merged as well, correct?</p> <p>This process is called cascading:</p> <p><a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations" rel="noreferrer">http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations</a></p> <p>In your User entity put <code>cascade={"merge"}</code> in the <code>@ManyToOne</code> annotation (or another type of association-definition you are using) for <code>$company</code> and <code>$privilege</code>.</p> <p>And if you want the detach call to be cascaded too (which is recommended), put in <code>cascade={"detach", "merge"}</code>.</p> <p>p.s.: Don't put such cascades on both sides of one association, you'll create an endless loop ;)</p> <p><strong>Edit:</strong></p> <p>This piece of code:</p> <pre><code>$entity = $cacheDriver-&gt;fetch($cacheId); $em-&gt;merge($entity); // &lt;- return $entity; </code></pre> <p>should be:</p> <pre><code>$entity = $cacheDriver-&gt;fetch($cacheId); $entity = $em-&gt;merge($entity); // &lt;- return $entity; </code></pre> <p>The thing with <code>merge()</code> is that it leaves the entity you pass as an argument untouched, and returns a <strong>new</strong> object that represents the managed version of the entity. So you want to use the return-value, not the argument you passed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload