sonata-project / EntityAuditBundle

Audit for Doctrine Entities
https://sonata-project.org
MIT License
633 stars 261 forks source link

Ignore related tables for auditiong #601

Open dmitrach opened 9 months ago

dmitrach commented 9 months ago

Feature Request

I would like to ignore a related table with M:M for auditing.

Actually it is not possible as I see and I cannot change the current library.

https://stackoverflow.com/questions/77801195/how-to-ignore-many-to-many-relationship-with-entityaudit-entityauditbundle?noredirect=1#comment137179292_77801195

<?php
/** @Entity **/
class User
{
    // ...

    /**
     * @ManyToMany(targetEntity="User", mappedBy="myFriends")
     **/
    private $friendsWithMe;

    /**
     * @ManyToMany(targetEntity="User", inversedBy="friendsWithMe")
     * @JoinTable(name="friends",
     *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@JoinColumn(name="friend_user_id", referencedColumnName="id")}
     *      )
     **/
    private $myFriends;

    public function __construct() {
        $this->friendsWithMe = new \Doctrine\Common\Collections\ArrayCollection();
        $this->myFriends = new \Doctrine\Common\Collections\ArrayCollection();
    }

    // ...
}
simple_things_entity_audit:
    audited_entities:
        - App\Entity\User
        - 
    global_ignore_tables:
        - friends

Thanks.

shepherdmat commented 6 months ago

How about instead of excluding individual tables, add an option to skip relationships.

simple_things_entity_audit:
    disable_associations: true
    audited_entities:
        - App\Entity\User
VincentLanglet commented 6 months ago

How about instead of excluding individual tables, add an option to skip relationships.

simple_things_entity_audit:
    disable_associations: true
    audited_entities:
        - App\Entity\User

Would it solve your issue @dmitrach ?

One issue I see here @shepherdmat is the fact it's all-or-nothing. Maybe the use case is to keep the behavior for some relations but exclude others relations.

github-actions[bot] commented 23 hours ago

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.