有没有可能有一个php类来扩展一个规则实体并持久化它?
示例:
/**
* @Entity
*/
class A {
/**
* @ORM\ManyToMany(targetEntity="C", mappedBy="parents")
*/
protected $children;
}
class B extends A {
...
}
class C {
/**
* @ORM\ManyToMany(targetEntity="A", inversedBy="children")
*/
protected $parents;
}
$b = new B();
$em->persist($b);发布于 2012-03-01 04:16:27
是的,这是可能的,这被称为inheritance mapping,但是子类必须显式声明为@Entity,并且它的映射也必须显式定义(如果子类添加了额外的属性)。
最常见的继承映射形式是单表继承,以下是Doctrine手册中的此类映射示例:
namespace MyProject\Model;
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
*/
class Person
{
// ...
}
/**
* @Entity
*/
class Employee extends Person
{
// ...
}https://stackoverflow.com/questions/9501755
复制相似问题