08-06-2023, 04:17 PM
I am learning about Symfony and Doctrine and created a simple site but I am stuck at this step.
I have two tables: `users` and `languages`
**Users** Contains: id, username ...
**Languages** Contains: user_id, language...
Here is a image of the two[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]:
[2]:
Now I am trying to fetch by language, like: get user who speaks both `english` **and** `french` and the result would return user id 2
In plain PHP i can do inner join with PDO, but I am trying to follow the doctrine syntax and this does not return the correct result
public function getMatchingLanguages ($a, $b) {
return $this->createQueryBuilder('u')
->andWhere('u.language = :val1 AND u.language = :val2')
->setParameter('val1', $a)
->setParameter('val2', $b)
->getQuery()
->execute();
}
I call this method in my controllers, and the query is pretty basic since I can not find a documentation how to do the joins as per my example
I have two tables: `users` and `languages`
**Users** Contains: id, username ...
**Languages** Contains: user_id, language...
Here is a image of the two[![enter image description here][1]][1]
[![enter image description here][2]][2]
[1]:
[2]:
Now I am trying to fetch by language, like: get user who speaks both `english` **and** `french` and the result would return user id 2
In plain PHP i can do inner join with PDO, but I am trying to follow the doctrine syntax and this does not return the correct result
public function getMatchingLanguages ($a, $b) {
return $this->createQueryBuilder('u')
->andWhere('u.language = :val1 AND u.language = :val2')
->setParameter('val1', $a)
->setParameter('val2', $b)
->getQuery()
->execute();
}
I call this method in my controllers, and the query is pretty basic since I can not find a documentation how to do the joins as per my example