I have a table of videos and in that table I have field comment which contains id of comment in other table, now I used join query to get that in one query, but how do I get that comment?
Here is my code:
$Actions = $this->EntityManager()->getRepository('AppBundle:Video')
->createQueryBuilder('V')
->join('AppBundle:VideoComment', 'VC')
->where('V.videoId = :VideoID')
->andWhere('VC.videoId = :VideoID')
->setParameter('VideoID', $VideoID)
->getQuery()
->getResult();
How do I get the actual comment from that joined entity?
Here is one proposal:
As you said you have a table 'video' and in that table there is a field 'comment' that contains the IDs of the comments. I suppose you have 'oneToMany' relation from 'video' to 'comment'. With this simple query you should be able to get all comments for a given VideoID. I didn't test this, but I think it should work. Try it out and adapt it as needed.
You can do what @cezar said earlier but with one little change: you have to define field to retrieve related entries from comments table. So, your query might look like this:
or you can do the similar stuff using query builder:
Both cases I described account for that Video and Comment entity might not be in formal relations (I mean their relations might not be described in your doctrine/orm file).