eav-manager icon indicating copy to clipboard operation
eav-manager copied to clipboard

[UserBundle] We can't override User entity

Open FabienSalles opened this issue 6 years ago • 1 comments

Hello,

I tried to update User entity. I created a new class :

use CleverAge\EAVManager\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
 
/**
 * Class User
 *
 * @package Jardiland\CleverAge\EAVManager\UserBundle\Entity
 *
 * @ORM\Entity(repositoryClass="Jardiland\CleverAge\EAVManager\UserBundle\Repository\Doctrine\DoctrineUserRepository")
 * @ORM\Table(name="eavmanager_user")
 */
class User extends BaseUser
{
 
}

I also created a doctrine listener to define the original class to mappedSuperClass in order to create doctrine inheritance :

use CleverAge\EAVManager\UserBundle\Entity\User;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;

class UserListener
{
    /**
     * Update User entity
     * @param LoadClassMetadataEventArgs $eventArgs
     */
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();

        if ($classMetadata->getName() !== User::class) {
            return;
        }

        $classMetadata->isMappedSuperclass = true;
    }
}

But when I tried to test my doctrine mapping with bin/console doctirne:schema:update --dump-sql, I had this error :

[Doctrine\ORM\Mapping\MappingException]                                                                                                           
  It is illegal to put an inverse side one-to-many or many-to-many association on mapped superclass 'CleverAge\EAVManager\UserBundle\Entity\User#f  
  amilyPermissions'.      

I think, it would be nice to have the mapping of the $familyPermissions property with an inversedBy attribute instead of its opposite : mappedBy

FabienSalles avatar Jul 05 '18 15:07 FabienSalles

You need to use your listener to also change every relation between any class and the user class. I will make this override easier in future versions.

VincentChalnot avatar Jul 09 '18 12:07 VincentChalnot