symfony - Symfony2 : How to auto update associated entity field with entity listener? -


I have some entities with intangible classes: EntityDated which means that the unit has 4 commons fields Are: created , updated , created_ and updated_by when I update the unit and when I Updating the entity, I want to update 'update data' and ' update ' and ' update_by .

I have been calling a service my listener:

  public function preUpdate (PreUpdateEventArgs $ eventArgs) {$ token = $ this- & gt; Container-> Get ('security.context') - & gt; getToken (); $ Unit = $ eventArgs-> GetEntity (); $ em = $ eventArgs- & gt; GetEntityManager (); $ Uow = $ em- & gt; GetUnitOfWork (); If (is_subclass_of ($ unit, 'kiwi \ bundle \ training bundle \ existance \' existed)) {$ entity-> Setuped (new \ Datetime ()); $ Entity-> setUpdatedBy ($ token- & gt; getUser () - & gt; getUsername ()); $ Meta = $ em- & gt; Mill class metadata (get_class ($ institution)); $ Uow- & gt; Recomputing Sensitivity Change ($ Meta, $ unit); }}   

This works perfectly is not connected to any institutions with simple entities but I try to add an example, I add an entity "response" to the array of $ reactions of my unit "question") I have the following error:

  Notice: Undefined Index: 0000000060e7f05700000000e7f2194b in C: \ wamp \ www \ kiwi \ vendor \ doctrine \ orm \ lib \ doctrine \ ORM \ unitOfWork.php line 1359   

The problem is that Khit unit $ em- & gt; Continuous () but by behavior: cascade = "persist" And as the Doctor says about recomputeSingleEntityChangeSet ():

Managed a managed organization Must be a unit. If the unit is already a change set since this method is applied during a committed cycle then the change sets are added. The changes which were found in this method can be strong.

So obviously the problem here is that my organization is not manageable. How do I manage it?

To insert both of them, and update, I have to change the two points:

  • Use onFlush () , preFlush ()
  • Add recomputeSingleEntityChangeSet () after each change < / Ul>

    New code:

      Public Function on Furnish (OnFlushEventArgs $ eventArgs) {$ token = $ this- & gt; Container - & gt; Get ('security.context') - & gt; getToken (); $ em = $ eventArgs- & gt; GetEntityManager (); $ Uow = $ em- & gt; GetUnitOfWork (); // Insert foreach ($ uow-> GetScheduledEntityInsertions) as a unit) {if (is_subclass_of ($ unit, 'kiwi' bundle \ trainingbundle entity) '') {$ entity-> Set (new \ Datetime ()); $ Entity-> setCreatedBy ($ token- & gt; getUser () - & gt; getUsername ()); $ Institution- & gt; Set updated (new \ Datetime ()); $ Entity-> setUpdatedBy ($ token- & gt; getUser () - & gt; getUsername ()); $ Meta = $ em- & gt; Mill class metadata (get_class ($ institution)); $ Uow- & gt; Recomputing Sensitivity Change ($ Meta, $ unit); }} // Updates foreach ($ uow- & gt; getScheduledEntityUpdates () as entity) {if_subclass_of ($ unit, 'kiwi bundle \ trainingbundle entity entity')) {$ entity-> setUpdated (new \ date time ()); $ Entity-> setUpdatedBy ($ token- & gt; getUser () - & gt; getUsername ()); $ Meta = $ em- & gt; Mill class metadata (get_class ($ institution)); $ Uow- & gt; Recomputing Sensitivity Change ($ Meta, $ unit); }}}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -