【发布时间】:2016-08-18 13:55:22
【问题描述】:
我使用 Symfony 3。我有一个父类 Licence,它有一些字段:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Licence
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(
* type="string",
* unique=true,
* length=30,
* nullable=false
* )
*/
protected $licenceKey;
}
我有一个扩展这个的子类。当然,它具有相同的字段,但我需要将它们存储在特定位置的数据库中: 所以我写了以下内容:
namespace AppBundle\Entity\LicenceCase\FirstLicenceCase;
use AppBundle\Entity\Licence as BaseLicence;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="lic_first")
* @ORM\InheritanceType("SINGLE_TABLE")
*/
class FirstLicenceCase extends BaseLicence
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
public function getLicenceKey()
{
return $this->licenceKey;
}
public function setLicenceKey($licenceKey)
{
$this->licenceKey = $licenceKey;
}
}
我需要获取任何特定许可案例的唯一列。我将为每个具有不同字段和方法的 LicenceCase 创建新类。但是使用此代码,我的数据库中没有正确的列。我该如何解决这个问题?
【问题讨论】:
-
您在子类中指定了父类的类注释。我的意思是表和继承类型。你应该按照这个例子:docs.doctrine-project.org/projects/doctrine-orm/en/latest/…
标签: php orm doctrine-orm symfony