php - Symfony2 Doctrine Error: Invalid PathExpression. Must be a StateFieldPathExpression -
well looking kind of might resolve problem, after still getting same error.
i trying news database in selected category. relation between news , categories many-to-many on doctrine.
<?php //news namespace core\databasebundle\entity; use doctrine\orm\mapping orm; class sfnews { private $date; private $header; private $content; private $contentplain; private $id; private $sfusers; private $sfuploadedfiles; private $sfcategories; public function __construct() { $this->sfuploadedfiles = new \doctrine\common\collections\arraycollection(); $this->sfcategories = new \doctrine\common\collections\arraycollection(); } // code removed public function setsfusers(\core\databasebundle\entity\users $sfusers = null) { $this->sfusers = $sfusers; return $this; } public function getsfusers() { return $this->sfusers; } public function addsfuploadedfile(\core\databasebundle\entity\sfuploadedfiles $sfuploadedfiles) { $this->sfuploadedfiles[] = $sfuploadedfiles; return $this; } public function removesfuploadedfile(\core\databasebundle\entity\sfuploadedfiles $sfuploadedfiles) { $this->sfuploadedfiles->removeelement($sfuploadedfiles); } public function getsfuploadedfiles() { return $this->sfuploadedfiles; } public function addsfcategorie(\core\databasebundle\entity\sfcategories $sfcategories) { $this->sfcategories[] = $sfcategories; return $this; } public function removesfcategorie(\core\databasebundle\entity\sfcategories $sfcategories) { $this->sfcategories->removeelement($sfcategories); } public function getsfcategories() { return $this->sfcategories; } } //categories namespace core\databasebundle\entity; use doctrine\orm\mapping orm; class sfcategories { private $name; private $id; //code removed public function getid() { return $this->id; } private $sfnews; public function __construct() { $this->sfnews = new \doctrine\common\collections\arraycollection(); } public function addsfnews(\core\databasebundle\entity\sfnews $sfnews) { $this->sfnews[] = $sfnews; return $this; } public function removesfnews(\core\databasebundle\entity\sfnews $sfnews) { $this->sfnews->removeelement($sfnews); } public function getsfnews() { return $this->sfnews; } //code removed }
code trying use is:
$sfcategory = $this->em->getrepository("coredatabasebundle:sfcategories")->findoneby(array("url"=>$category)); $qb = $this->em->createquerybuilder('p'); $qb ->select('p') ->from("coredatabasebundle:sfnews","p") ->where($qb->expr()->like('p.sfcategories', ':id')) ->setparameter('id', $sfcategory->getid()) ->setmaxresults($count) ->orderby('p.date', 'desc'); $r = $qb->getquery(); return $r->getresult();
orm via xml
<?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="core\databasebundle\entity\sfnews" table="sf_news"> <id name="id" type="integer" column="id"> <generator strategy="identity"/> </id> <field name="date" type="datetime" column="date" nullable="true"/> <field name="header" type="string" column="header" length="255" nullable="false"/> <field name="content" type="text" column="content" nullable="false"/> <field name="contentplain" type="text" column="content_plain" nullable="false"/> <one-to-one field="sfusers" target-entity="users"> <join-columns> <join-column name="sf_users_id" referenced-column-name="id"/> </join-columns> </one-to-one> <many-to-many field="sfuploadedfiles" target-entity="sfuploadedfiles" inversed-by="sfnews"> <join-table name="sf_news_has_sf_uploaded_files"> <join-columns> <join-column name="sf_news_id" referenced-column-name="id"/> </join-columns> <inverse-join-columns> <join-column name="sf_uploaded_files_id" referenced-column-name="id"/> </inverse-join-columns> </join-table> </many-to-many> <many-to-many field="sfcategories" target-entity="sfcategories" inversed-by="sfnews"> <join-table name="sf_news_has_sf_categories"> <join-columns> <join-column name="sf_news_id" referenced-column-name="id"/> </join-columns> <inverse-join-columns> <join-column name="sf_categories_id" referenced-column-name="id"/> </inverse-join-columns> </join-table> </many-to-many> </entity> </doctrine-mapping> <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="core\databasebundle\entity\sfcategories" table="sf_categories"> <id name="id" type="integer" column="id"> <generator strategy="identity"/> </id> <field name="name" type="string" column="name" length="255" nullable="false"/> <field name="url" type="string" column="url" length="255" nullable="false"/> <field name="visible" type="boolean" column="visible" nullable="true"/> <many-to-many field="sfnews" target-entity="sfnews" mapped-by="sfcategories"/> </entity> </doctrine-mapping>
error getting is:
[semantical error] line 0, col 50 near 'sfcategories': error: invalid pathexpression. must statefieldpathexpression.
im looking forward kind of way solve problem. thanks
Comments
Post a Comment