php - Doctrine 2.2.2 - issue inserting multiple entries at once? -


i unable work correctly. insert entries twice , never set project_id in project_data table, 0. have tried inserting multiple ways..

like so

//... work $project = new psd_model_entity_project(); $project->setstatusid($this->_em->find("psd_model_entity_status", '3')); $project->adddata('hello', $data->data->hello);  $this->_em->persist($project); $this->_em->flush(); 

and so

$project = new psd_model_entity_project(); $project->setstatusid($this->_em->find("psd_model_entity_status", '3'));  $project_data = new psd_model_entity_project_data('hello', $data->data->hello,$project);  $this->_em->persist($project); $this->_em->persist($project_data); $this->_em->flush(); 

doctrine model:

<?php    use doctrine\orm\mapping orm;  /**  * psd_model_entity_project  * @entity  * @table(name="project")  */ class psd_model_entity_project {     /**      * @var integer $project_id      * @id @column(type="integer")      * @generatedvalue(strategy="auto")      */     private $project_id;      /**      * @var integer $dependent      * @column(type="integer")      */     private $dependent;      /**      * @var integer $iduser      * @column(type="integer")      */     private $iduser;      /**      * @var datetime $created      * @column(type="datetime")      */     private $created;      /**      * @var datetime $modified      * @column(type="datetime")      */     private $modified;      /**      * @var psd_model_entity_status      * @manytoone(targetentity="psd_model_entity_status")      * @joincolumn(name="status_id", referencedcolumnname="status_id")      */     private $status_id;      /**      * @onetomany(targetentity="psd_model_entity_project_data", mappedby="project_id", cascade={"all"}, indexby="name")      */     private $data;      public function __construct()     {         $this->data = new \doctrine\common\collections\arraycollection();     }       public function adddata($name, $value)     {         $this->data[$name] = new psd_model_entity_project_data($name, $value, $this);     }      /**      * project_id      *      * @return integer       */     public function getprojectid()     {         return $this->project_id;     }      /**      * set dependent      *      * @param integer $dependent      * @return psd_model_entity_project      */     public function setdependent($dependent)     {         $this->dependent = $dependent;         return $this;     }      /**      * dependent      *      * @return integer       */     public function getdependent()     {         return $this->dependent;     }      /**      * set iduser      *      * @param integer $iduser      * @return psd_model_entity_project      */     public function setiduser($iduser)     {         $this->iduser = $iduser;         return $this;     }      /**      * iduser      *      * @return integer       */     public function getiduser()     {         return $this->iduser;     }      /**      * set created      *      * @param datetime $created      * @return psd_model_entity_project      */     public function setcreated($created)     {         $this->created = $created;         return $this;     }      /**      * created      *      * @return datetime       */     public function getcreated()     {         return $this->created;     }      /**      * set modified      *      * @param datetime $modified      * @return psd_model_entity_project      */     public function setmodified($modified)     {         $this->modified = $modified;         return $this;     }      /**      * modified      *      * @return datetime       */     public function getmodified()     {         return $this->modified;     }      /**      * set status_id      *      * @param psd_model_entity_status $statusid      * @return psd_model_entity_project      */     public function setstatusid(\psd_model_entity_status $statusid = null)     {         $this->status_id = $statusid;         return $this;     }      /**      * status_id      *      * @return psd_model_entity_status       */     public function getstatusid()     {         return $this->status_id;     } }  <?php    use doctrine\orm\mapping orm;  /**  * psd_model_entity_project_data  * @entity  * @table(name="project_data")  */ class psd_model_entity_project_data {     /**      * @var integer $project_data_id      * @id @column(type="integer")      * @generatedvalue(strategy="auto")      */     private $project_data_id;      /**      * @var integer $project_id      * @column(type="integer")      * @manytoone(targetentity="psd_model_entity_project", inversedby="data")      */     private $project_id;      /**      * @var string $name      * @column(type="string")      */     private $name;      /**      * @var string $value      * @column(type="string")      */     private $value;       public function __construct($name, $value, $project)     {         $this->name = $name;         $this->value = $value;         $this->project_id = $project;     }      /**      * set project_id      *      * @param psd_model_entity_project $projectid      * @return psd_model_entity_project_data      */     public function setprojectid(\psd_model_entity_project $projectid = null)     {         $this->project_id = $projectid;         return $this;     }      /**      * project_id      *      * @return integer       */     public function getprojectid()     {         return $this->project_id;     }      /**      * set name      *      * @param string $name      * @return psd_model_entity_project_data      */     public function setname($name)     {         $this->name = $name;         return $this;     }      /**      * name      *      * @return string       */     public function getname()     {         return $this->name;     }      /**      * set value      *      * @param string $value      * @return psd_model_entity_project_data      */     public function setvalue($value)     {         $this->value = $value;         return $this;     }      /**      * value      *      * @return string       */     public function getvalue()     {         return $this->value;     } } 

i believe data model properties should marked protected instead of private, according docs.

the reference $project_id inside psd_model_entity_project_data has this:

/**  * @column(type="integer")  * @manytoone(targetentity="psd_model_entity_project", inversedby="data")  */ 

you try changing column joincolumn:

/**  * @joincolumn()  * @manytoone(targetentity="psd_model_entity_project", inversedby="data")  */ 

btw, have similar model , didn't need inversedby; it's been while since have touched doctrine may not make difference whatsoever :)


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -