Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log an entity that has collections?

I want to log all changes of an entity. I looked into Loggable doctrine extension as provided by the StofDoctrineExtensionsBundle.

I got it working for fields that store simple data, e.g. string and integers. But my entity also has ManyToMany relationship to another entity, e.g. Tags.

I am getting this error:

InvalidMappingException: Cannot versioned [tags] as it is collection in object - Hn\AssetDbBundle\Entity\Asset

Is there a way to log an entity with its relationships? I don't mind switching to another bundle.

like image 816
k0pernikus Avatar asked Jul 23 '14 11:07

k0pernikus


1 Answers

Currently no bundles/extensions have this functionality out of the box. One option would be to implement it yourself. This can be done by making use of Doctrine Listeners. Particularly you need to listen to postUpdate and postPersist events - these happen when entity is updated and created and store your Tags there.

Another option is to get rid of ManyToMany relationship. For this create an intermediate entity AssetTag that would have OneToMany relationship to both Asset and Tag. After this is done, you can use EntityAudit Doctrine Extension, which supports this type of relationships.

like image 85
Konstantin Pereiaslov Avatar answered Oct 13 '22 21:10

Konstantin Pereiaslov