php - How this MySQL query will be in Doctrine DQL? -


i have below query in mysql:

select * (orders) inner join links on orders.ref_id = links.id inner join users on links.user_id = users.id links.user_id=2 

and 3 entities in symfony: order, link, user.

how can write in doctrine query builder?

            $repo = $em->getrepository('orderbundle:order');             $querybuilder=$repo->createquerybuilder('o');             $query = $querybuilder             ->select('o, l, u')             ->innerjoin('c.ref_id', 'l')             ->innerjoin('l.user_id', 'u')             ->where('u.id=1')             ->getquery(); 

this doesn't work. got below error:

[semantical error] line 0, col 84 near 'u u.id': error: class orderbundle\entity\order has no association named user_id

i trying 2 hours , make me angry... in advance.

my order entity:

<?php // src/orderbundle/entity/order.php  namespace orderbundle\entity;  use doctrine\orm\mapping orm; use symfony\component\validator\constraints\datetime;  /**  * @orm\entity  * @orm\table(name="orders")  */      class order     {         /**          * @orm\id          * @orm\column(type="integer")          * @orm\generatedvalue(strategy="auto")          */         protected $id;           /**          * @orm\manytoone(targetentity="orderbundle\entity\order")          * @orm\joincolumn(name="ref_id", referencedcolumnname="id")          */         protected $ref_id;          /**          * @orm\column(type="datetime")          */         protected $date_created;          /**          * @orm\column(type="string", length=60)          */         protected $email;          /**          * @orm\column(type="string", length=60)          */         protected $email2;          /**          * @orm\column(type="integer")          */         protected $service;          /**          * @orm\column(type="string", length=20)          */     protected $fromlang;      /**      * @orm\column(type="string", length=20)      */     protected $tolang;      /**      * @orm\column(type="boolean")      */     protected $academic;      /**      * @orm\column(type="string", length=40)      */     protected $discipline;      /**      * @orm\column(type="text")      */     protected $notes;      /**      * @orm\column(type="string")      */     protected $file;      /**      * @orm\column(type="integer")      */     protected $status;      /**      * @orm\column(type="integer")      */     protected $cost;      /**      * @orm\column(type="string", length=2)      */     protected $site;      public function __construct()     {         $this->date_created = new datetime();     }      /**      * id      *      * @return integer      */     public function getid()     {         return $this->id;     }      /**      * set datecreated      *      * @param \datetime $datecreated      *      * @return order      */     public function setdatecreated($datecreated)     {         $this->date_created = $datecreated;          return $this;     }      /**      * datecreated      *      * @return \datetime      */     public function getdatecreated()     {         return $this->date_created;     }      /**      * set email      *      * @param string $email      *      * @return order      */     public function setemail($email)     {         $this->email = $email;          return $this;     }      /**      * email      *      * @return string      */     public function getemail()     {         return $this->email;     }      /**      * set email2      *      * @param string $email2      *      * @return order      */     public function setemail2($email2)     {         $this->email2 = $email2;          return $this;     }      /**      * email2      *      * @return string      */     public function getemail2()     {         return $this->email2;     }      /**      * set refid      *      * @param integer $refid      *      * @return order      */     public function setrefid($refid)     {         $this->ref_id = $refid;          return $this;     }      /**      * refid      *      * @return integer      */     public function getrefid()     {         return $this->ref_id;     }      /**      * set service      *      * @param integer $service      *      * @return order      */     public function setservice($service)     {         $this->service = $service;          return $this;     }      /**      * service      *      * @return integer      */     public function getservice()     {         return $this->service;     }      /**      * set fromlang      *      * @param string $fromlang      *      * @return order      */     public function setfromlang($fromlang)     {         $this->fromlang = $fromlang;          return $this;     }      /**      * fromlang      *      * @return string      */     public function getfromlang()     {         return $this->fromlang;     }      /**      * set tolang      *      * @param string $tolang      *      * @return order      */     public function settolang($tolang)     {         $this->tolang = $tolang;          return $this;     }      /**      * tolang      *      * @return string      */     public function gettolang()     {         return $this->tolang;     }      /**      * set academic      *      * @param boolean $academic      *      * @return order      */     public function setacademic($academic)     {         $this->academic = $academic;          return $this;     }      /**      * academic      *      * @return boolean      */     public function getacademic()     {         return $this->academic;     }      /**      * set discipline      *      * @param string $discipline      *      * @return order      */     public function setdiscipline($discipline)     {         $this->discipline = $discipline;          return $this;     }      /**      * discipline      *      * @return string      */     public function getdiscipline()     {         return $this->discipline;     }      /**      * set notes      *      * @param string $notes      *      * @return order      */     public function setnotes($notes)     {         $this->notes = $notes;          return $this;     }      /**      * notes      *      * @return string      */     public function getnotes()     {         return $this->notes;     }      /**      * set file      *      * @param string $file      *      * @return order      */     public function setfile($file)     {         $this->file = $file;          return $this;     }      /**      * file      *      * @return string      */     public function getfile()     {         return $this->file;     }      /**      * set status      *      * @param integer $status      *      * @return order      */     public function setstatus($status)     {         $this->status = $status;          return $this;     }      /**      * status      *      * @return integer      */     public function getstatus()     {         return $this->status;     }      /**      * set cost      *      * @param integer $cost      *      * @return order      */     public function setcost($cost)     {         $this->cost = $cost;          return $this;     }      /**      * cost      *      * @return \cost      */     public function getcost()     {         return $this->cost;     }      /**      * set site      *      * @param string $site      *      * @return order      */     public function setsite($site)     {         $this->site = $site;          return $this;     }      /**      * site      *      * @return string      */     public function getsite()     {         return $this->site;     } } 


Comments