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...