有可能是我理解与教义协会。参考编号没有更新与Doctrine协会
我有一个一流的:
class FitComments
{
/**
* @var integer
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="SEQ_FIT_COMMENTS", allocationSize=1, initialValue=1)
*/
private $id;
/**
*
* @ORM\OneToMany(targetEntity="FitCommentsId",mappedBy="comments",cascade={"persist"})
*
*/
private $elements;
/****/
public function __construct()
{
$this->elements=new ArrayCollection();
}
public function getElements()
{
return $this->elements;
}
....
}
并有另一个类,元素ID列表中的评论链接。
/**
* FitCommentsId
* @ORM\Entity
*/
class FitCommentsId
{
/**
* @var integer
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="SEQ_FIT_COMMENTS_ID", allocationSize=1, initialValue=1)
*/
private $id;
/**
*
* @ORM\ManyToOne(targetEntity="FitComments",inversedBy="elements")
* @ORM\JoinColumn(name="COMMENTS_ID",referencedColumnName="ID")
*/
private $comments;
....
}
我用:
$comments=new FitComment();
$commentId=new FitCommentId();
....
$comments->getElements()->add($commentId);
....
$entityManager->persist($comment);
$entityManager->flush();
但是我有一个错误。 $ commentId->评论为空。它必须正常填写$ comment-> id。
如果我必须手工填写$ commentId-> comments,关联不是很有用。
也许我不明白机制。
注:SGDB是Oracle。