How to log an entity that has collections?
Asked Answered
M

1

11

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.

Megilp answered 23/7, 2014 at 11:2 Comment(1)
Here is a related issue on GitHub.Footage
H
7

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.

Hysterotomy answered 7/7, 2015 at 22:35 Comment(1)
Note that Loggable can detect the creation of the intermediate entity too.Footage

© 2022 - 2024 — McMap. All rights reserved.