DoctrineExtensions icon indicating copy to clipboard operation
DoctrineExtensions copied to clipboard

Loggable : Allow to log OneToMany relations

Open fdiedler opened this issue 3 years ago • 5 comments

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,

fdiedler avatar Feb 11 '22 13:02 fdiedler

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 avatar Feb 11 '22 17:02 franmomu

@franmomu Sorry, I think it was only for ManyToMany relations.

What a shame ! it would be a very nice feature :)

fdiedler avatar Feb 11 '22 18:02 fdiedler

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 avatar Jul 22 '22 13:07 ThomasLabstep

@ThomasLabstep we'd be interested in your collection implementation, any chance you could provide a repository for that code?

whizzrd avatar Aug 02 '22 05:08 whizzrd

@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.

ThomasLabstep avatar Aug 02 '22 07:08 ThomasLabstep

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.

github-actions[bot] avatar Jan 29 '23 09:01 github-actions[bot]