我有以下两个Doctrine实体,其中TestInheritanceChild扩展了TestInheritanceParent,并且它们都是单个表继承的一部分:
/**
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="reference_type", type="string")
* @ORM\DiscriminatorMap({
* "disc1" = "TestInheritanceParent",
* "disc2" = "TestInheritanceChild"
* })
*/
class TestInheritanceParent
{
/**
* @var
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(name="id", type="integer")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="ReferenceOne")
* @ORM\JoinColumn(name="reference_id", referencedColumnName="reference_one_id")
*/
protected $reference;
}
/**
* @ORM\Entity()
*/
class TestInheritanceChild
extends TestInheritanceParent
{
/**
* @ORM\OneToOne(targetEntity="ReferenceTwo")
* @ORM\JoinColumn(name="reference_id", referencedColumnName="reference_two_id")
*/
protected $reference;
}
我想重写子类中的一对一关联,以便将InheritanceTestParent类型的对象的引用属性与ReferenceOne实体相关联,并将InheritanceTestChild类型的对象的引用属性进行关联与ReferenceTwo实体。 但是,如果我看一下元数据,则会得到父级和子级实体的以下关联映射:
array:1 [
"reference" => array:19 [
"fieldName" => "reference"
"targetEntity" => "ReferenceOne"
"joinColumns" => array:1 [
0 => array:6 [
"name" => "reference_id"
"unique" => false
"nullable" => true
"onDelete" => null
"columnDefinition" => null
"referencedColumnName" => "reference_one_id"
]
]
"mappedBy" => null
"inversedBy" => null
"cascade" => []
"orphanRemoval" => false
"fetch" => 2
"type" => 1
"isOwningSide" => true
"sourceEntity" => "TestInheritanceParent"
"isCascadeRemove" => false
"isCascadePersist" => false
"isCascadeRefresh" => false
"isCascadeMerge" => false
"isCascadeDetach" => false
"sourceToTargetKeyColumns" => array:1 [
"reference_id" => "reference_one_id"
]
"joinColumnFieldNames" => array:1 [
"reference_id" => "reference_id"
]
"targetToSourceKeyColumns" => array:1 [
"reference_one_id" => "reference_id"
]
]
]
我的问题是:如何覆盖子实体中的父注释?我已经尝试使用@ORM \ AssociationOverride注释,该注释也不起作用。
有什么想法吗?
我当前正在使用Doctrine 2.6 ...