在坚持一对多关系时,我从Doctrine收到错误。我在这里看到过类似的问题,但不幸的是答案没有帮助。
这是错误:
<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
定义:
/**
* @OneToMany(targetEntity="Scripts", mappedBy="ScriptsVersions",cascade={ "persist","remove"} )
**/
protected $ScriptsVersions;
构造
public function __construct() {
$this->ScriptsVersions = new \Doctrine\Common\Collections\ArrayCollection();
}
设置器:
public function setScriptsVersions(ScriptsVersions $ScriptsVersions){
if(!$this->ScriptsVersions->contains($ScriptsVersions)){
$this->ScriptsVersions[] = $ScriptsVersions;
$ScriptsVersions->setScripts($this);
}
}
如果在分配之后转储$ this-&gt; ScriptsVersions类,它会显示Doctrine\Common\Collections\Collection
,但UnityOfWork会以某种方式获取对象而不是ArrayCollection ......
答案 0 :(得分:1)
正如我在评论中提到的那样 - 您粘贴的代码中的 private void Loop()
{
while (threadRunning)
{
BeginInvoke(new MethodInvoker(() => timeLabel.Text = DateTime.Now.ToString()));
Thread.Sleep(100);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
threadRunning = false;
thread.Join();
}
并未指向正确的实体类。很高兴我可以帮忙:)。