php - Symfony2 - Join with Native Query -
i'm trying putting first join symfony2 createnativequery.
i made first 1 without join , there's no problem.
i think lost steps, follow code:
$rsm = new resultsetmapping; $rsm ->addentityresult('art\articlebundle\entity\articledata', 'ad') // ->addentityresult('art\articlebundle\entity\article', 'a') // ->addfieldresult('ad', 'id', 'article_data_id') ->addjoinedentityresult('art\articlebundle\entity\article', 'a', 'ad', 'article') ->addfieldresult('a', 'date_article', 'datearticle'); $query = $this->_em->createnativequery( 'select ad.id article_data_id, ad.title, ad.abstract ' . 'from art_article_data ad ' . 'inner join art_article on (ad.article_id = a.id) ' , $rsm ); return $query->getresult();
it returns following error: sqlstate[42s22]: column not found: 1054 unknown column 'a.id' in 'on clause'")
.
why a.id
unknown? within entity , table. step have lost ?
as @javad required, below there's article entity
<?php namespace art\articlebundle\entity; use doctrine\orm\mapping orm; use doctrine\common\collections\arraycollection; use art\articlebundle\entity\articletype; use art\articlebundle\entity\articlecategory; use art\articlebundle\entity\articledata; use art\articlebundle\entity\articlehasbrand; /** * article * * @orm\entity(repositoryclass="art\articlebundle\entity\repository\articlerepository") * @orm\table(name="art_article", options={"collate"="utf8_general_ci", "charset"="utf8"}) * @orm\haslifecyclecallbacks() */ class article { function __construct() { $this->articles__article_data = new arraycollection(); $this->articles_article_has_brand = new arraycollection(); $this->setdateinsert(new \datetime); $this->setdateedit(new \datetime); $this->setisvisible(1); $this->setismain(0); $this->setord(0); } function __tostring() { // $this->datearticle; } /** * @var integer * * @orm\id * @orm\column(name="id", type="integer", options={"unsigned"=true}) * @orm\generatedvalue(strategy="auto") */ private $id; /** * @var \stdclass * * @orm\manytoone(targetentity="articletype", inversedby="article_types__article") * @orm\joincolumn(name="article_type_id", referencedcolumnname="id", nullable=false) * @orm\generatedvalue(strategy="identity") */ private $articletype; /** * @var \stdclass * * @orm\manytoone(targetentity="articlecategory", inversedby="article_categories__article") * @orm\joincolumn(name="article_category_id", referencedcolumnname="id", nullable=true) * @orm\generatedvalue(strategy="identity") */ private $articlecategory; /** * @var \datetime * * @orm\column(name="date_article", type="date", nullable=true) */ private $datearticle; /** * @var string * * @orm\column(name="url", type="string", length=127, nullable=true) */ private $url; /** * @var \datetime * * @orm\column(name="date_insert", type="datetime", nullable=false) */ private $dateinsert; /** * @var \datetime * * @orm\column(name="date_edit", type="datetime", nullable=true) */ private $dateedit; /** * @var boolean * * @orm\column(name="is_visible", type="boolean", options={"unsigned"=true, "default"=1}, nullable=false) */ private $isvisible; /** * @var boolean * * @orm\column(name="is_main", type="boolean", options={"unsigned"=true, "default"=0}, nullable=false) */ private $ismain; /** * @var integer * * @orm\column(name="ord", type="integer", options={"unsigned"=true, "default"=0}, nullable=true) */ private $ord; /** * @var object * * @orm\onetomany(targetentity="articledata", mappedby="article") */ private $articles__article_data; /** * @var object * * @orm\onetomany(targetentity="articlehasbrand", mappedby="article") */ private $articles_article_has_brand; /** * id * * @return integer */ public function getid() { return $this->id; } /** * set datearticle * * @param \datetime $datearticle * @return article */ public function setdatearticle($datearticle) { $this->datearticle = $datearticle; return $this; } /** * datearticle * * @return \datetime */ public function getdatearticle() { return $this->datearticle; } /** * url * * @return string */ public function geturl() { return $this->url; } /** * set dateinsert * * @param string $url * @return article */ public function seturl($url) { $this->url = $url; } /** * set dateinsert * * @param \datetime $dateinsert * @return article */ public function setdateinsert($dateinsert) { $this->dateinsert = $dateinsert; return $this; } /** * dateinsert * * @return \datetime */ public function getdateinsert() { return $this->dateinsert; } /** * set dateedit * * @param \datetime $dateedit * @return article */ public function setdateedit($dateedit) { $this->dateedit = $dateedit; return $this; } /** * dateedit * * @return \datetime */ public function getdateedit() { return $this->dateedit; } /** * set isvisible * * @param boolean $isvisible * @return article */ public function setisvisible($isvisible) { $this->isvisible = $isvisible; return $this; } /** * isvisible * * @return boolean */ public function getisvisible() { return $this->isvisible; } /** * set ismain * * @param boolean $ismain * @return article */ public function setismain($ismain) { $this->ismain = $ismain; return $this; } /** * ismain * * @return boolean */ public function getismain() { return $this->ismain; } /** * set ord * * @param integer $ord * @return article */ public function setord($ord) { $this->ord = $ord; return $this; } /** * ord * * @return integer */ public function getord() { return $this->ord; } /** * set articletype * * @param \art\articlebundle\entity\articletype $articletype * @return article */ public function setarticletype(articletype $articletype = null) { $this->articletype = $articletype; return $this; } /** * articletype * * @return \art\articlebundle\entity\articletype */ public function getarticletype() { return $this->articletype; } /** * set articlecategory * * @param \art\articlebundle\entity\articlecategory $articlecategory * @return article */ public function setarticlecategory(articlecategory $articlecategory = null) { $this->articlecategory = $articlecategory; return $this; } /** * articlecategory * * @return \art\articlebundle\entity\articlecategory */ public function getarticlecategory() { return $this->articlecategory; } /** * add articles__article_data * * @param \art\articlebundle\entity\articledata $articlesarticledata * @return article */ public function addarticlesarticledata(articledata $articlesarticledata) { $this->articles__article_data[] = $articlesarticledata; return $this; } /** * remove articles__article_data * * @param \art\articlebundle\entity\articledata $articlesarticledata */ public function removearticlesarticledata(articledata $articlesarticledata) { $this->articles__article_data->removeelement($articlesarticledata); } /** * articles__article_data * * @return \doctrine\common\collections\collection */ public function getarticlesarticledata() { return $this->articles__article_data; } /** * add articles_article_has_brand * * @param \art\articlebundle\entity\articlehasbrand $articlesarticlehasbrand * @return article */ public function addarticlesarticlehasbrand(articlehasbrand $articlesarticlehasbrand) { $this->articles_article_has_brand[] = $articlesarticlehasbrand; return $this; } /** * remove articles_article_has_brand * * @param \art\articlebundle\entity\articlehasbrand $articlesarticlehasbrand */ public function removearticlesarticlehasbrand(articlehasbrand $articlesarticlehasbrand) { $this->articles_article_has_brand->removeelement($articlesarticlehasbrand); } /** * articles_article_has_brand * * @return \doctrine\common\collections\collection */ public function getarticlesarticlehasbrand() { return $this->articles_article_has_brand; } }
Comments
Post a Comment