Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I can tell, there's nothing wrong with the code you've shown. But if the <code>$oLastCall</code> object becomes detached between the first and second code blocks, you have to re-attach (merge) it to the manager so that it detects the changes for the second flush.</p> <p>Merging can be done in this way:</p> <pre><code>$oLastCallMerged = $oMan-&gt;merge($oLastCall); $oLastCallMerged-&gt;setDateEnd(new \DateTime('now')); $oMan-&gt;flush(); </code></pre> <p>You can also check the state (MANAGED/NEW/DETACHED/REMOVED) of an object using this code:</p> <pre><code>$oMan-&gt;getUnitOfWork()-&gt;getEntityState($oLastCall); </code></pre> <p>&nbsp;</p> <p>If that doesn't help (i.e. detachment of the object isn't your problem), you need to give more info about the context this code runs in and any errors you get. Is this code part of a <a href="http://symfony.com/doc/current/cookbook/console/console_command.html" rel="nofollow">Console Command</a> or a regular web-app Controller? Do you get any output or errors when running it in 'dev' environment? (Check <code>.../app/logs/dev.log</code>.) Does the <code>$oLastCall</code> object stay in memory while waiting for the stuff that takes some minutes, or do you reload it from somewhere?</p> <p>Btw, objects doesn't magically get detached by themselves. They'll only be detached if you load them from a different source than the entity manager (for example storing them in the session between requests) OR if you explicitly detach them by calling <code>$oMan-&gt;detach($entity)</code> or <code>$oMan-&gt;clear()</code>.</p> <h3>Edit</h3> <p>You can also check if Doctrine detects the change by echoing out the changeset using <code>$oMan-&gt;getUnitOfWork()-&gt;getEntityChangeSet($oLastCall)</code> before and after the change, e.g:</p> <pre><code>error_log(json_encode($oMan-&gt;getUnitOfWork()-&gt;getEntityChangeSet($oLastCall))); $oLastCall-&gt;setDateEnd(new \DateTime('now')); error_log(json_encode($oMan-&gt;getUnitOfWork()-&gt;getEntityChangeSet($oLastCall))); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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