gpt4 book ai didi

symfony - targetEntity 在不同的包中时出错

转载 作者:行者123 更新时间:2023-12-04 10:05:08 26 4
gpt4 key购买 nike

当我尝试执行 ./app/console doctrine:migrate:diff 时出现以下错误:

 [Doctrine\ORM\Mapping\MappingException]                                        
Class VNN\CoreBundle\Entity\Game is not a valid entity or mapped super class.

这是导致它的行:
/**
* @ORM\ManyToOne(targetEntity="VNN\CoreBundle\Entity\Game")

这是我类(class)的相关部分:
<?php

namespace VNN\PressboxBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Query\Expr\OrderBy;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Type;
use VNN\CoreBundle\Entity\Game;

/**
* VNN\PressboxBundle\Entity\Event
*
* @ORM\Table(name="event")
* @ORM\Entity
*/
class Event
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @ORM\ManyToOne(targetEntity="VNN\CoreBundle\Entity\Game")
* @ORM\JoinColumn(name="core_game_id", referencedColumnName="game_id")
**/
private $coreGame;

我理解的不是它找不到 VNN\CoreBundle\Entity\Game ,就是这样 Game不是有效实体。所以这里是 Game.php :
<?php

namespace VNN\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* VNN\CoreBundle\Entity\Game
*
* @ORM\Table(name="games")
* @ORM\Entity
*/
class Game
{
/**
* @var integer $id
*
* @ORM\Column(name="game_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var integer $homeSchoolId
*
* @ORM\Column(name="home_school_id", type="integer")
*/
private $homeSchoolId;

/**
* @var integer $awaySchoolId
*
* @ORM\Column(name="away_school_id", type="integer")
*/
private $awaySchoolId;

/**
* @ORM\ManyToOne(targetEntity="School")
* @ORM\JoinColumn(name="home_school_id", referencedColumnName="school_id")
**/
private $homeSchool;

/**
* @ORM\ManyToOne(targetEntity="School")
* @ORM\JoinColumn(name="away_school_id", referencedColumnName="school_id")
**/
private $awaySchool;

/**
* @ORM\ManyToOne(targetEntity="Sport")
* @ORM\JoinColumn(name="sport_id", referencedColumnName="sport_id")
**/
private $sport;

/**
* @var integer $datetime
*
* @ORM\Column(name="game_datetime")
*/
private $datetime;

/**
* @var integer $homeScore
*
* @ORM\Column(name="home_score", type="integer")
*/
private $homeScore;

/**
* @var integer $awayScore
*
* @ORM\Column(name="away_score", type="integer")
*/
private $awayScore;

public function getId()
{
return $this->id;
}

public function getHomeSchool()
{
if ($this->homeSchoolId > 0) {
return $this->homeSchool;
} else {
return FALSE;
}
}

public function getAwaySchool()
{
if ($this->awaySchoolId > 0) {
return $this->awaySchool;
} else {
return FALSE;
}
}

public function recordIsValid()
{
if (!($this->homeSchoolId > 0)) {
return FALSE;
}

if (!($this->awaySchoolId > 0)) {
return FALSE;
}

return TRUE;
}

public function getSport()
{
return $this->sport;
}

public function getHumanDatetime()
{
$date = new \DateTime($this->datetime);
return $date->format('F d, Y g:ia');
}

public function getDatetime()
{
$date = new \DateTime($this->datetime);
return $date->format('m/d/Y g:i:s a');
}

public function getOpposingSchoolWithRespectToSchoolName($schoolName)
{
if ($schoolName == $this->getHomeSchool()->getName()) {
return $this->getAwaySchool();
} else {
return $this->getHomeSchool();
}
}

public function getHomeScore()
{
return $this->homeScore;
}

public function getAwayScore()
{
return $this->awayScore;
}
}

为什么不喜欢 Game ?

更新:当我尝试对另一个跨捆绑实体做同样的事情时,我又遇到了同样的问题。我找到了 this post ,但是添加前导斜线修复对我来说并没有像它对那里的 OP 所做的那样。

最佳答案

我已经成功地使用了跨捆绑实体关系,没有任何问题。如果您禁用了自动映射,您需要告诉学说每个包含实体的包。

所以在 app/config.yml 你需要有这样的:

doctrine:
orm:
auto_mapping: true

或这个:
doctrine:
orm:
auto_mapping: false
entity_managers:
default:
mappings:
VNNCoreBundle: ~
VNNPressboxBundle: ~

检查您的数据库是否存在包的表。您也可以尝试运行 ./app/console doctrine:generate:entities --force并确保它运行没有错误

编辑

我检查了我的代码和领先的 /没有必要。还有 use声明是多余的。

关于symfony - targetEntity 在不同的包中时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10372078/

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