php - Doctrine & Symfony2 join multiple tables -


i've been struggling doing multiple join in dql. here code:

    $query = $em->createquery(         'select k          appbundle:keyword k          join k.company c          join k.entry e          c.user = :id          order k.name asc'     )->setparameter('id',$user_id); 

but gives me "notice: undefined index: entry", when executing it.

here keyword entity:

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * keyword */ class keyword { /**  * @var integer  */ private $id;  /**  * @var string  */ private $name;   /**  * id  *  * @return integer   */ public function getid() {     return $this->id; }  /**  * set name  *  * @param string $name  * @return keyword  */ public function setname($name) {     $this->name = $name;      return $this; }  /**  * name  *  * @return string   */ public function getname() {     return $this->name; } /**  * @var \doctrine\common\collections\collection  */ private $user;  /**  * constructor  */ public function __construct() {     $this->user = new \doctrine\common\collections\arraycollection(); }  /**  * add user  *  * @param \appbundle\entity\user $user  * @return keyword  */ public function adduser(\appbundle\entity\user $user) {     $this->user[] = $user;      return $this; }  /**  * remove user  *  * @param \appbundle\entity\user $user  */ public function removeuser(\appbundle\entity\user $user) {     $this->user->removeelement($user); }  /**  * user  *  * @return \doctrine\common\collections\collection   */ public function getuser() {     return $this->user; }  /**  * set user  *  * @param \appbundle\entity\user $user  * @return keyword  */ public function setuser(\appbundle\entity\user $user = null) {     $this->user = $user;      return $this; } /**  * @var \doctrine\common\collections\collection  */ private $company;   /**  * add company  *  * @param \appbundle\entity\company $company  * @return keyword  */ public function addcompany(\appbundle\entity\company $company) {     $this->company[] = $company;      return $this; }  /**  * remove company  *  * @param \appbundle\entity\company $company  */ public function removecompany(\appbundle\entity\company $company) {     $this->company->removeelement($company); }  /**  * company  *  * @return \doctrine\common\collections\collection   */ public function getcompany() {     return $this->company; }  /**  * set company  *  * @param \appbundle\entity\company $company  * @return keyword  */ public function setcompany(\appbundle\entity\company $company = null) {     $this->company = $company;      return $this; } /**  * @var \doctrine\common\collections\collection  */ private $entry;   /**  * add entry  *  * @param \appbundle\entity\entry $entry  * @return keyword  */ public function addentry(\appbundle\entity\entry $entry) {     $this->entry[] = $entry;      return $this; }  /**  * remove entry  *  * @param \appbundle\entity\entry $entry  */ public function removeentry(\appbundle\entity\entry $entry) {     $this->entry->removeelement($entry); }  /**  * entry  *  * @return \doctrine\common\collections\collection   */ public function getentry() {     return $this->entry; } /**  * @var \doctrine\common\collections\collection  */ private $ranking;   /**  * add ranking  *  * @param \appbundle\entity\ranking $ranking  * @return keyword  */ public function addranking(\appbundle\entity\ranking $ranking) {     $this->ranking[] = $ranking;      return $this; }  /**  * remove ranking  *  * @param \appbundle\entity\ranking $ranking  */ public function removeranking(\appbundle\entity\ranking $ranking) {     $this->ranking->removeelement($ranking); }  /**  * ranking  *  * @return \doctrine\common\collections\collection   */ public function getranking() {     return $this->ranking; } } 

and entry entity:

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /** * entry  */ class entry { /**  * @var integer  */ private $id;  /**  * @var string  */ private $path;   /**  * id  *  * @return integer   */ public function getid() {     return $this->id; }  /**  * set path  *  * @param string $path  * @return entry  */ public function setpath($path) {     $this->path = $path;      return $this; }  /**  * path  *  * @return string   */ public function getpath() {     return $this->path; }  /**  * @var \appbundle\entity\keyword  */ private $keyword;   /**  * set keyword  *  * @param \appbundle\entity\keyword $keyword  * @return entry  */ public function setkeyword(\appbundle\entity\keyword $keyword = null) {     $this->keyword = $keyword;      return $this; }  /**  * keyword  *  * @return \appbundle\entity\keyword   */ public function getkeyword() {     return $this->keyword; } /**  * @var \doctrine\common\collections\collection  */ private $ranking;  /**  * constructor  */ public function __construct() {     $this->ranking = new \doctrine\common\collections\arraycollection(); }  /**  * add ranking  *  * @param \appbundle\entity\ranking $ranking  * @return entry  */ public function addranking(\appbundle\entity\ranking $ranking) {     $this->ranking[] = $ranking;      return $this; }  /**  * remove ranking  *  * @param \appbundle\entity\ranking $ranking  */ public function removeranking(\appbundle\entity\ranking $ranking) {     $this->ranking->removeelement($ranking); }  /**  * ranking  *  * @return \doctrine\common\collections\collection   */ public function getranking() {     return $this->ranking; } } 

btw i'm pretty new symfony , doctrine. appreciate kinds of help!

you need provide mapping information each attribute in model class provide entity mapping class. take @ http://doctrine-common.readthedocs.org/en/latest/reference/annotations.html

each of model classes need @orm\entity annotation tell doctrine mapped entity. case have:

/** * entry * @orm\entity */ class entry { ... 

then each attribute want mapped database needs @orm\column annotation. example:

/**  * @var integer  * @orm\id @orm\column @orm\generatedvalue  */ private $id;  /**  * @var string  * @orm\column(type="string")  */ private $path; 

then need create relationship mapping annotations relationships between models (keyword -> company, keyword -> entry etc), using 1 of mappings on here http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html

once have correct mappings use command line tool app/console doctrine:schema:update make sure model in sync database.

your dql seems fine once have correct mappings in place might have better luck.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -