Answer the question
In order to leave comments, you need to log in
How to join unrelated entities in QueryBuilder?
An elementary request, with which, for some reason, difficulties arose.
So, there are two entities (tables) that are not related to each other (there is no foreign key):
You need to build a query like this through createQueryBuilder:
SELECT post.title, view.views FROM post
JOIN view ON post.title = view.post
WHERE view.views > 0;
public function getPosts(): array
{
return $this->createQueryBuilder('p')
->join(View::class, 'v', 'ON', 'p.title = v.post')
->where('v.views > 0')
->getQuery()
->getResult()
;
}
QueryException: [Syntax Error] line 0, col 61: Error: Expected end of string, got 'ON'
Answer the question
In order to leave comments, you need to log in
return $this->createQueryBuilder('p')
->join(View::class, 'v', 'WITH', 'p.title = v.post')
->where('v.views > 0')
->getQuery()
->getResult()
;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question