[英]Doctrine ArrayCollection with one-to-many throws an error
I get an error from Doctrine when persisting a one-to-many relationship. 坚持一对多关系时,我从教义中得到一个错误。 I've seen similar questions here, but the answers don't help, unfortunately. 我在这里看到了类似的问题,但是不幸的是,答案并没有帮助。
Here is the error: 这是错误:
<b>Fatal error</b>: Uncaught exception 'Doctrine\ORM\ORMInvalidArgumentException' with message 'Expected value of type "Doctrine\Common\Collections\Collection|array" for association field "Entities\Scripts#$ScriptsVersions", got "Entities\ScriptsVersions" instead.' in H:\SERVER\htdocs\10pages\www\php\Vendors\doctrine\orm\lib\Doctrine\ORM\ORMInvalidArgumentException.php:206
Definition: 定义:
/**
* @OneToMany(targetEntity="Scripts", mappedBy="ScriptsVersions",cascade={ "persist","remove"} )
**/
protected $ScriptsVersions;
Constructor: 构造函数:
public function __construct() {
$this->ScriptsVersions = new \Doctrine\Common\Collections\ArrayCollection();
}
Setter: 二传手:
public function setScriptsVersions(ScriptsVersions $ScriptsVersions){
if(!$this->ScriptsVersions->contains($ScriptsVersions)){
$this->ScriptsVersions[] = $ScriptsVersions;
$ScriptsVersions->setScripts($this);
}
}
If I dump the class of $this->ScriptsVersions after assigning it, it says Doctrine\\Common\\Collections\\Collection
, but somehow UnityOfWork gets the object instead of the ArrayCollection... 如果我在分配$ this-> ScriptsVersions类后转储该类,它说Doctrine\\Common\\Collections\\Collection
,但不知何故UnityOfWork获取对象而不是ArrayCollection。
As I mentioned in the comment - the targetEntity
in the code you pasted is not pointing at the correct entity class. 正如我在评论中提到的那样,您粘贴的代码中的targetEntity
没有指向正确的实体类。 Glad I could help :) 很高兴我能帮上忙 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.