0
我試圖在數據庫表中插入一條新記錄,而不是替換表中的記錄。 (目前我在這個表中有一條記錄)。任何想法爲什麼?這裏是我的查詢:不插入作爲新記錄而是替換以前的記錄
public function setExperimentData($name, $type, $description) {
$updateQuery = $this->repository->createQueryBuilder('ud')
->update()
->set('ud.name', $this->em->createQueryBuilder()->expr()->literal($name))
->set('ud.type', $this->em->createQueryBuilder()->expr()->literal($type))
->set('ud.description', $this->em->createQueryBuilder()->expr()->literal($description))
->getQuery();
$updateQuery->execute();
}
是的,我曾嘗試以下(實驗()是實體):
$experiment = new Experiments();
$experiment->setName($experimentName);
$experiment->setDescription($experimentDescription);
$experiment->setPrimaryinvestigator($primaryInvestigator);
然後我得到以下錯誤:
捕致命錯誤:傳遞給Test \ HelloBundle \ Entity \ Experiments :: setPrimaryinvestigator()的參數1必須是Test \ HelloBundle \ Entity \ Users的實例
這是我在實體類主要調查二傳手:
public function setPrimaryinvestigator(\Test\HelloBundle\Entity\Users $primaryinvestigator = null)
{
$this->primaryinvestigator = $primaryinvestigator;
return $this;
}
我到底做錯了什麼?
UPDATE:
及其整數passed.E,G 1是PrimaryInvestigator的id。
mattexx檢查下面的帖子。 –