Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my solution. It's not that elegant as I was hoping to get, but anyway at least it works. So, in my solution we first check if the emails collection is dirty (meaning that some emails were added and/or deleted). If it's not dirty we still need to check if any changes to the existing emails were made. I was hoping to use some existing API for that, but it seems there are none of them for this case. So, I decided to check my data manually for changes. Code example follows.</p> <pre><code>/** * * @Template() */ public function editAction($id, Request $request) { $repository = $this-&gt;getDoctrine()-&gt;getRepository('AcmeBundle:Person'); $person = $repository-&gt;find($id); if (!$person) { throw $this-&gt;createNotFoundException('No person found for id '.$id); } if ($request-&gt;isMethod('POST')) { $form-&gt;bind($request); if ($form-&gt;isValid()) { $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); // isDirty() will be true if emails were added or deleted if ($person-&gt;getEmails()-&gt;isDirty()) { $person-&gt;setUpdated(new \DateTime(date('Y-m-d H:i:s'))); } else { $uow = $em-&gt;getUnitOfWork(); // as no one suggested a working solution, I just decided // to check entity by entity, field by field // if anything is changed, we'll mark $person as updated foreach($person-&gt;getEmails() as $item) { $orig = $uow-&gt;getOriginalEntityData($item); if ($item-&gt;getEmail() != $orig['email']) { $person-&gt;setUpdated(new \DateTime(date('Y-m-d H:i:s'))); break; } } } $em-&gt;flush(); } } return array('form' =&gt; $form-&gt;createView(), 'person' =&gt; $person); } </code></pre> <p>If anyone has any idea how to avoid one by one entity check, I would greatly appreciate if you share such a solution.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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