我不确定出了什么问题。在试图复制你的问题时,我做不到。
进入一个symfony 2.0.15项目,我使用了以下实体
<?php
namespace Peter\SandboxBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="request")
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"base" = "Base"})
*/
class Requete
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
protected $discr;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set discr
*
* @param string $discr
*/
public function setDiscr($discr)
{
$this->discr = $discr;
}
/**
* Get discr
*
* @return string
*/
public function getDiscr()
{
return $this->discr;
}
}
/**
* @ORM\Table(name="base")
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"base" = "Base",
* "prosante" = "ProSante"})
*/
abstract class Base extends Requete {}
/**
* @ORM\Table(name="prosante")
* @ORM\Entity
*/
class ProSante extends Base {}
然后安装 DDL,看起来像这样(由 产生doctrine:schema:update
)
CREATE TABLE request (id INT AUTO_INCREMENT NOT NULL, discr VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE base (id INT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE prosante (id INT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
ALTER TABLE base ADD CONSTRAINT FK_C0B4FE61BF396750 FOREIGN KEY (id) REFERENCES request(id) ON DELETE CASCADE;
ALTER TABLE prosante ADD CONSTRAINT FK_420DF702BF396750 FOREIGN KEY (id) REFERENCES request(id) ON DELETE CASCADE
然后做了一个简单的命令来测试插入
// ...
protected function execute( InputInterface $input, OutputInterface $output )
{
$p = new ProSante();
$em = $this->getContainer()->get('doctrine')->getEntityManager();
$em->persist( $p );
$em->flush();
$output->writeln( 'All done' );
}
// ...
当我在控制台看到“All done”时,我直接查看了数据库,结果粘贴在下面
mysql> select * from prosante;
+----+
| id |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
mysql> select * from base;
+----+
| id |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
mysql> select * from request;
+----+----------+
| id | discr |
+----+----------+
| 1 | prosante |
+----+----------+
1 row in set (0.00 sec)
不知道从这里去哪里。