How to register an entity with collections?

I want to register all entity changes. I looked at the Loggable extension provided by the StofDoctrineExtensionsBundle.

I got it for fields that store simple data, for example. string and integers. But my entity also has ManyToMany related to another object, for example. Tags

I get this error:

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

Is there a way to register an entity with its relationship? I do not mind switching to another package.

+6
source share
1 answer

Currently, no packages / extensions have this functionality out of the box. One option is to implement it yourself. This can be done using Doctrine Listeners . In particular, you need to listen for postUpdate and postPersist - this happens when an entity is updated and created and stores its tags there.

Another option is to get rid of the ManyToMany relationship. To do this, create an intermediate AssetTag object that has AssetTag related to Asset and Tag . After that, you can use the EntityAudit Doctrine Extension that supports this type of relationship.

+4
source

Source: https://habr.com/ru/post/972696/


All Articles