I have two classes, AbstractProject and Project. AbstractProject is an abstract class, and is extended by Project. When I run doctrine:schema:validate it says my schema is fine, even though my Project table only has an Id field. Everything was working fine until a couple days ago I went through and renamed a few classes, but now I can't seem to get doctrine to generate the database columns for the inherited properties. My twig templates access the properties without complaint (they come up blank, but dont complain about the property or method not existing), and I can use the inherited properties in the parent class, yet doctrine refuses to recognize them. Classes and mappings below, appreciate another set of eyes on it maybe I'm missing something simple.
*If it helps, when I try to generate entities for dpProjectBundle (where the AbstractProject lives) I get an error: "Bundle "dpProjectBundle" does not contain any mapped entities." I am not sure if it should consider the mappedSuperclasses as mapped entities, but maybe that is a sign of the problem?
*while pasting the code I noticed I was missing "use Doctrine\ORM\Mapping as ORM;" in the Project class, still says my schema is valid after adding that line, but maybe that was an issue? I also tried clearing the cache, and the doctrine:cache:clear-metadata command
RESOLVED* In my config.yml I am using multiple entity managers, and I had not yet associated the dpProjectBundle(AbstractProject) with an entity manager. Once I did that doctrine realized my schema was invalid and when I ran the update my columns are present now.
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:
Project:
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;
}
}
Project Mapping:
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: { }