我有两个类,AbstractProject和Project。 AbstractProject是一个抽象类,由Project扩展。当我运行doctrine:schema:验证它说我的架构很好,即使我的Project表只有一个Id字段。一切都工作正常,直到几天前我经历并重命名了几个类,但现在我似乎无法获得学说来为继承的属性生成数据库列。我的twig模板访问属性而没有抱怨(它们出现空白,但不抱怨不存在的属性或方法),并且我可以使用父类中的继承属性,但是doctrine拒绝识别它们。下面的类和映射,欣赏另一组眼睛,也许我错过了一些简单的东西。
*如果有帮助,当我尝试为dpProjectBundle(AbstractProject所在的位置)生成实体时,我收到一个错误:"" Bundle" dpProjectBundle"不包含任何映射实体。"我不确定它是否应该将mappedSuperclasses视为映射实体,但也许这是问题的标志?
*在粘贴代码时我注意到我遗失了#34;使用Doctrine \ ORM \ Mapping作为ORM;"在Project类中,仍然说我的架构在添加该行后是有效的,但也许这是一个问题?我还尝试清除缓存和doctrine:cache:clear-metadata命令
分辨* 在我的config.yml我使用多个实体管理器,我还没有将dpProjectBundle(AbstractProject)与实体管理器相关联。一旦我做了那个学说,我意识到我的架构是无效的,当我运行更新时,我的列现在就出现了。
orm:
default_entity_manager: dp
entity_managers:
dp:
connection: dp
mappings:
dpProjectBundle: ~ // <-- this line was missing, and caused my problems
devUserBundle: ~
devSecurityBundle: ~
devProjectBundle: ~
devWebsiteBundle: ~
local:
connection: local
mappings:
项目:
namespace dev\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use dp\ProjectBundle\Entity\AbstractProject;
/**
* Project
*/
class Project extends AbstractProject
{
/**
* @var integer
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @var \Doctrine\Common\Collections\Collection
*/
protected $tasks;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->tasks = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add tasks
*
* @param \dev\ProjectBundle\Entity\Task $tasks
* @return Project
*/
public function addTask(\dev\ProjectBundle\Entity\Task $tasks)
{
$this->tasks[] = $tasks;
return $this;
}
/**
* Remove tasks
*
* @param \dev\ProjectBundle\Entity\Task $tasks
*/
public function removeTask(\dev\ProjectBundle\Entity\Task $tasks)
{
$this->tasks->removeElement($tasks);
}
/**
* Get tasks
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTasks()
{
return $this->tasks;
}
}
AbstractProject:
namespace dp\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* AbstractProject
*/
abstract class AbstractProject
{
public function __construct()
{
$this->createdAt = new \DateTime();
}
/**
* @var string
*/
protected $name;
/**
* @var \DateTime
*/
protected $createdAt;
/**
* @var \DateTime
*/
protected $completedAt;
/**
* Set name
*
* @param string $name
* @return AbstractProject
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return AbstractProject
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set completedAt
*
* @param \DateTime $completedAt
* @return AbstractProject
*/
public function setCompletedAt($completedAt)
{
$this->completedAt = $completedAt;
return $this;
}
/**
* Get completedAt
*
* @return \DateTime
*/
public function getCompletedAt()
{
return $this->completedAt;
}
/**
* @var string
*/
protected $description;
/**
* Set description
*
* @param string $description
* @return AbstractProject
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}
项目映射:
dev\ProjectBundle\Entity\Project:
type: entity
table: dev_projects
oneToMany:
tasks:
targetEntity: Task
mappedBy: project
cascade: [persist, remove]
id:
id:
type: integer
id: true
generator:
strategy: AUTO
lifecycleCallbacks: { }
AbstractProject Mapping:
dp\ProjectBundle\Entity\AbstractProject:
type: mappedSuperclass
fields:
name:
type: string
length: 255
description:
type: text
nullable: true
createdAt:
type: datetime
completedAt:
type: datetime
nullable: true
lifecycleCallbacks: { }
答案 0 :(得分:0)
在我的config.yml中我使用多个实体管理器,而我还没有将dpProjectBundle(AbstractProject)与实体管理器相关联。一旦我做了那个学说,我意识到我的架构是无效的,当我运行更新时,我的列现在就出现了。