gpt4 book ai didi

php - Doctrine 2继承映射找不到基表或 View

转载 作者:搜寻专家 更新时间:2023-10-31 21:19:53 25 4
gpt4 key购买 nike

我试图使用Docrtrine映射对继承进行建模,但得到一个错误。
我想绘制简单的关系图。UserEntity将是其他用户相关实体(如GuestUserEntityAdminEntity)的基本实体。
我有以下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 ...
}

对于 AdminEntity我有以下xml映射
<?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 {

}

每当我试图查询用户时,我会得到以下错误
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mngit.AdminEntity' 

我的配置有什么问题?

最佳答案

首先,我可以假设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();

希望能帮上忙

关于php - Doctrine 2继承映射找不到基表或 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55075124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com