Skip to main content

Symfony2 Doctrine query


Hi stackoverflow friends



I'm new in symfony2 , I don't know how to write a below query in symfony2 using createQuery()




select * from Post inner join Category on Post.category_id=Category.id inner join Priority on Post.priority_id=Priority.id order by priority_number desc



I used repository class,in which ,wrote a function




public function findAllOrderedByPriorityPost()
{

return $this->getEntityManager()
->createQuery('select p,c,pr from RodasysfourmBundle:Post p inner join
RodasysfourmBundle:Category c inner join RodasysfourmBundle:Priority pr order by pr.priorityNumber desc')
->getResult();
}



when I used this function,I got the below error




[Semantical Error] line 0, col 85 near 'c inner join': Error: Identification Variable RodasysfourmBundle:Category used in join path expression but was not defined before.



Also which method is best using this query in a custom repository or as a service?



any help appreciated.


Source: Tips4allCCNA FINAL EXAM

Comments

  1. DQL in doctrine2 won't know how to join tables if you specify the name of a referenced entity. You can only work with one entity and its fields (which may have relations).

    select p,c,pr from RodasysfourmBundle:Post p inner join
    p.Category c inner join c.Priority pr order by pr.priorityNumber desc

    ReplyDelete
  2. I think this link could answer your question: Error: Identification Variable used in join path expression but was not defined before

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?