symfony - Does not insert as a new record instead replaces a previous record -


i have tried insert new record in database table instead keeps replacing record in table. (currently have single record in table). ideas why? here's query:

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(); }   

yes have tried following (experiments() entity):

$experiment = new experiments(); $experiment->setname($experimentname);         $experiment->setdescription($experimentdescription); $experiment->setprimaryinvestigator($primaryinvestigator); 

then following error:

catchable fatal error: argument 1 passed test\hellobundle\entity\experiments::setprimaryinvestigator() must instance of test\hellobundle\entity\users

here setter primary investigator in entity class:

public function setprimaryinvestigator(\test\hellobundle\entity\users $primaryinvestigator = null)     {         $this->primaryinvestigator = $primaryinvestigator;          return $this;     } 

what doing wrong?

update:

its integer passed.e,g, 1 id of primaryinvestigator.

i not think querybuilder supports insert queries @ time. assuming have experiment entity setters, have tried

public function setexperimentdata($name, $type, $description) {     $em = $this->getdoctrine()->getmanager();     $experiment = new experiment();     $experiment->setname($name);     $experiment->settype($type);     $experiment->setdescription($description);     $em->persist($experiment);     $em->flush(); }   

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -