原则2继承映射找不到基表或视图

时间:2019-03-09 07:39:51

标签: php symfony doctrine-orm doctrine

我正在尝试使用</body> </html> 映射为继承建模,但出现错误。

我想映射简单的关系。 Docrtrine将成为其他与用户相关的实体(如UserEntityGuestUserEntity)的基础实体。

我为AdminEntity

具有以下映射
BaseUserEntity

定义了以下实体类

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                   https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

    <entity name="MngIt\User\Domain\BaseUserEntity"
            repository-class="MngIt\User\Infrastructure\UserEntityRepository"
            inheritance-type="SINGLE_TABLE"
            table="mng_users">

        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>

        <discriminator-column name="discriminator"/>
        <discriminator-map>
            <discriminator-mapping value="buyer" class="MngIt\Admin\Domain\AdminEntity"/>
        </discriminator-map>

        <field name="login" type="string" column="login"/>
        <field name="username" type="string" column="username"/>
        <field name="email" type="string" column="email"/>
        <field name="balance" type="string" column="balance"/>
        <field name="lang" type="string" column="lang"/>
        <field name="timeDifference" type="string" column="timedifference"/>

    </entity>
</doctrine-mapping>

对于class BaseUserEntity extends \MngIt\Base\Domain\BaseEntity { protected $username; protected $login; protected $email; protected $balance; protected $timeDifference; /** * @return mixed */ public function getUsername() { return $this->username; } // getters ... } ,我具有以下xml映射

AdminEntity

该类定义如下

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                   https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">

    <entity name="MngIt\Buyer\Domain\BuyerEntity"
            repository-class="MngIt\Admin\Infrastructure\AdminEntityRepository">

    </entity>
</doctrine-mapping>

每当我尝试查询用户时,都会出现以下错误

<?php

namespace MngIt\Buyer\Domain;

use MngIt\User\Domain\BaseUserEntity;

class AdminEntity extends BaseUserEntity {

}

我的配置出了什么问题?

1 个答案:

答案 0 :(得分:1)

首先,我可以假设BaseUserEntity类只是一个包含公共属性的基本实体。在这种情况下,最好将此类设为abtract

abstract class BaseUserEntity extends \MngIt\Base\Domain\BaseEntity {

我还可以看到您已经为该实体定义了自定义存储库

repository-class="MngIt\User\Infrastructure\UserEntityRepository",因为这是基础实体,所以无需定义存储库。

如果已配置,请考虑清除缓存。

$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcuCache());
$config->setResultCacheImpl(new \Doctrine\Common\Cache\ApcuCache());
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcuCache());

要清除缓存,您可以运行命令

php app/console cache:clear

或以编程方式

$cacheDriver = $entityManager->getConfiguration()->getResultCacheImpl();
$deleted = $cacheDriver->deleteAll();

希望有帮助