Symfony 2/Doctrine 2:同一个表的两个实体,使用一个赞成另一个

Yer*_*oon 7 php symfony doctrine-orm

在我的Symfony2应用程序中,我将大部分实体提取到一个单独的库中,我使用composer进行安装.

这个库没有依赖于Symfony2(但是依赖于Doctrine,因为我使用了注释),因为我想在其他非Symfony2项目中使用它.

该库包含一个ClientUser映射到client_users表的实体.在我的Symfony2应用程序中,我想使用相同的ClientUser实体进行身份验证.这需要我实施Symfony\Component\Security\Core\User\UserInterface.

问题是我希望同时具有"Symfony2-agnostic" "Symfony-aware" ClientUser实体(两者都应该映射到同一个表).我试图从ClientUserAbstract实体扩展这两个类,但它没有用.

<?php
namespace My\Library\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\MappedSuperClass
 */
class ClientUserAbstract {

    // all my fields here
}
Run Code Online (Sandbox Code Playgroud)

我的"Symfony2-agnostic"实体:

<?php
namespace My\Library\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class ClientUser extends ClientUserAbstract {

    // nothing here, it's empty
}
Run Code Online (Sandbox Code Playgroud)

我的"Symfony2-aware"实体:

<?php
namespace Vendor\Bundle\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Entity
 */
class ClientUser extends ClientUserAbstract implements UserInterface {

    // all methods that Symfony requires because of the UserInterface here:
    public function getRoles();
    public function getPassword();
    public function getSalt();
    public function getUsername();
    public function eraseCredentials();
}
Run Code Online (Sandbox Code Playgroud)

我的Symfony 2应用程序现在检测到两个指向同一个表的实体,并以异常方式失败.我要么告诉我的Symfony2应用程序"忽略"我的My\Library\Entity\ClientUser,要么我需要一种方法来扩展它.有任何想法吗?

Cer*_*rad 16

以防万一其他人有这个问题,这里是我的评论转换为答案:

对于给定的实体管理器,每个表严格一个实体.您需要创建第二个实体管理器并将其用于身份验证.

当然,我喜欢得到代表.