Loggable : Allow to log OneToMany relations
Hi,
I want to log changes from a OneToMany relation but I have an error message :
Cannot apply versioning to field [managedPeriods] as it is collection in object - App\Entity\XXX
And the mapping of my Entity :
/** * @ORM\OneToMany(targetEntity=ManagedPeriod::class, mappedBy="property", cascade={"persist", "remove"}, orphanRemoval=true) * @Gedmo\Versioned */ private $managedPeriods;
What is wrong ?
Thanks,
Hi @fdiedler, as explained in https://github.com/doctrine-extensions/DoctrineExtensions/blob/2def628a9a8304c1e7f56847a0b21778a3a9ed61/doc/annotations.md#gedmomappingannotationversioned-optional, you cannot use Versioned attribute/annotation in a collection.
Versioning a collection doesn't seem like an easy task.
@franmomu Sorry, I think it was only for ManyToMany relations.
What a shame ! it would be a very nice feature :)
Oh I did the collection implementation.
If anyone is interested, please reach me. It has some limitations and design decisions but it's doing the job of tracking add/remove just fine :)
@ThomasLabstep we'd be interested in your collection implementation, any chance you could provide a repository for that code?
@whizzrd Here you go: https://gist.github.com/ThomasLabstep/bb138d8f36a22265729f76d565ed317c
Feel free to tweak the implementation to fit your needs.
This implementation mimics ext_log_entries objectClass/objectId but with parent/child fields and action ADD/REMOVE.
You could probably adapt this code to inject these new fields directly into ext_log_entries if you want to keep everything in the same table. We chose to separate the 2. Can't really tell if it was a good or bad decision so far.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.