php - symfony Error: Expected =, <, <=, <>, >, >=, !=, got '.' -


i have query looks results obtained variable in controller.

$category = $request->request->get('category');  $catcontent = $em->getrepository('publicartelappbundle:content')->findbycategory($category);  public function findbycategory($category)     {         $em = $this->getentitymanager();          $dql = 'select c publicartel\appbundle\entity\content c';          if (!is_null($category)) {             $dql .= " c.categories.name = category";         }          $query = $this->getentitymanager()             ->createquery($dql)             ->sethydrationmode(\doctrine\orm\query::hydrate_array);          if (!is_null($category)) {             $query->setparameter('category', $category);         }          return $query->getresult();     } 

but when run action query error occurs:

[syntax error] line 0, col 71: error: expected =, <, <=, <>, >, >=, !=, got '.' 

select c publicartel\appbundle\entity\content c c.categories.name = category

$categories atribute entity content.

class content { private $categories;      public function __construct()     {         $this->categories = new \doctrine\common\collections\arraycollection();     }  public function addcategories(\publicartel\appbundle\entity\category $categories)     {         $this->categories[] = $categories;          return $this;     }      public function removecategories(\publicartel\appbundle\entity\category $categories)     {         $this->categories->removeelement($categories);     }      public function setcategories(\publicartel\appbundle\entity\category $categories = null)     {         $this->categories = $categories;          return $this;     }     public function getcategories()     {         return $this->categories;     } } 

the strange thing when get variable , error not appear.

$category = $request->query->get('category'); 

you cannot reference subobject way:

select c publicartel\appbundle\entity\content c c.categories.name = :category 

you need join prior , use alias of joined entity. this:

select c, cat publicartel\appbundle\entity\content c join c.categories cat cat.name = :category 

now, either use left join or join , should work.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -