【发布时间】:2018-01-31 15:40:54
【问题描述】:
当我尝试加入继承的类时,我从 Doctrine 收到 OutOfBoundsException 并显示上面的错误消息。
我定义了以下实体:
FormElement 是父类
/**
* @ORM\Entity()
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="ETYP_ID", type="integer")
* @ORM\DiscriminatorMap({
* 1 = "DatetimeElement",
* 3 = "ChoiceElement",
* 4 = "TextElement",
* 5 = "MatrixElement",
* 6 = "HtmlElement"
* })
* @Table(name="FORMELEMENT")
*/
abstract class Formelement {
/**
* @var integer
* @ORM\Id()
* @ORM\Column(name="ELE_ID", type="integer", nullable=false)
*/
private $elementId;
}
ChoiceElement 是一个子类
/**
* @ORM\Entity()
* @ORM\Table(name="CHOICEELEMENT")
*/
class ChoiceElement extends Formelement {
/**
* @var integer
* @ORM\Id()
* @ORM\Column(name="CHOE_ID", type="integer", nullable=false)
*/
private $id;
/**
* @var Choice[]|ArrayCollection
* @ORM\OneToMany(targetEntity="Choice", mappedBy="choiceElement")
*/
private $choices;
public function getChoices(){
return $this->choices;
}
}
Choice 在 ChoiceElement 上加入
/**
* Class Choice
* @package apps\dynfrm\models\Doctrine\entities
* @ORM\Entity()
* @ORM\Table(name="CHOICE")
*/
class Choice {
/**
* @var integer
* @ORM\Id()
* @ORM\Column(name="CHO_ID", type="integer", nullable=false)
*/
private $id;
/**
* @var ChoiceElement
* @ORM\ManyToOne(targetEntity="ChoiceElement", inversedBy="choices")
* @ORM\JoinColumn(name="CHOE_ID", referencedColumnName="CHOE_ID", nullable=false)
*/
private $choiceElement;
}
ChoiceElement 是一个FormElement 并且有多个Choices。一切正常,即使是对ChoiceElement::getChoices() 的调用。但是,当我尝试访问生成的 ArrayCollection 时,Doctrine 会抛出上述错误。
我已经使用调试器进行了一些挖掘,但我不明白这是一个错误还是预期的行为。
我真的希望有人可以在这里帮助我。
【问题讨论】:
标签: php inheritance doctrine-orm orm doctrine