【发布时间】:2014-02-12 15:08:44
【问题描述】:
在我的项目中,我有几个这样的class table inheritances:
namespace MyProject\Model;
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
*/
class Person
{
// ...
}
/** @Entity */
class Employee extends Person
{
// ...
}
我有一种方法可以根据具有公共 getter 的字段将实体转换为数组。这里的问题是我丢失了数组中的继承信息,因为鉴别器值没有存储在字段中。
所以我尝试了以下,希望学说会自动设置$disc:
class Person
{
// can I automatically populate this field with 'person' or 'employee'?
protected $discr;
public function getDiscr() { return $this->discr; }
public function setDiscr($disc) { $this->discr; }
// ...
}
有没有办法让这在教义中发挥作用?或者我需要在我的实体到数组方法中读取类元数据吗?
【问题讨论】:
标签: doctrine-orm