【发布时间】:2017-09-05 10:39:21
【问题描述】:
美好的一天。我已经在第二天了,我不明白这是怎么回事......我在运行时收到错误:
PHP 致命错误:未捕获的异常 'Doctrine\ORM\Mapping\MappingException' 带有消息'The 找不到目标实体 Entity\ItemsBags '实体\玩家#itemsBag'。'在 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:762 堆栈跟踪: #0./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php(1028): Doctrine\ORM\Mapping\MappingException::invalidTargetEntityClass('Entity\\ItemsBag...', 'Entity\\Players', 'itemsBag') #1./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(272): Doctrine\ORM\Mapping\ClassMetadataInfo->validateAssociations() #2./var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(251): Doctrine\ORM\Mapping\ClassMetadataFactory->validateRuntimeMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), 空值) #3./var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(332): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadM in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php 在第 762 行
当我检查教义和更新时,一切都很顺利:
root@comp:# php vendor/bin/doctrine orm:schema:update --force 更新 数据库架构... 数据库架构更新成功! “4”个查询 被处决
root@comp:# php vendor/bin/doctrine orm:validate-schema [映射] OK - 映射文件正确。 [数据库] OK - 数据库架构与映射文件同步。
我尝试清除缓存,删除代理并重新生成它们,但没有任何结果...
root@comp:# php vendor/bin/doctrine orm:clear-cache:metadata
Clearing ALL Metadata cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:clear-cache:query
Clearing ALL Query cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:clear-cache:result
Clearing ALL Result cache entries
Successfully deleted cache entries.
root@comp:# php vendor/bin/doctrine orm:generate-proxies
Processing entity "Entity\Objects"
Processing entity "Entity\Weapons"
Processing entity "Entity\ItemsBags"
Processing entity "Entity\Players"
Processing entity "Entity\Translations"
Processing entity "Entity\Worlds"
Processing entity "Entity\Tiles"
Processing entity "Entity\WorldStructures"
Proxy classes generated to "/tmp"
Players.php
namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @Entity
* @Table(name="players")
*
*/
class Players{
...
/**
* @var ItemsBags
*
* @OneToOne(targetEntity="ItemsBags", mappedBy="player")
*/
private $itemsBag;
...
}
ItemsBags.php
namespace Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
*
* @Entity
* @Table(name="item_bags")
*
*/
class ItemsBags{
...
/**
* @var Players
*
* @OneToOne(targetEntity="Players", inversedBy="itemsBag")
* @JoinColumn(name="player_id", referencedColumnName="id")
*/
private $player;
...
}
请告诉我,我做错了什么?
【问题讨论】:
-
我会尝试删除 @JoinColumn 行,看看是否有帮助。
-
无效(
-
您可以尝试使用完全限定名称:
@OneToOne(targetEntity="\Entity\ItemsBags", mappedBy="player")和@OneToOne(targetEntity="\Entity\Players", inversedBy="itemsBag")。虽然它似乎确实在那里寻找他们...... -
你配置了psr-4根吗?在你的作曲家文件中寻找 psr-4
-
我尝试使用完全限定名称,但这也没有效果。 @Sarcoma我不太明白你的问题......我在我的项目中只使用学说,使用作曲家。我这样初始化学说:pastebin.com/AYB7Zvnd
标签: php doctrine-orm backend