
Left join with query builder
In my “new” job – we’re working entirely with Symfony, thus I decided to get my hands dirty and rewrite my eternal “Car Expenses” project in Symfony.
What I found challenging was finding how exactly to make joins in doctrine. So after some digging, trial and error, ended up doing this – code is in a method inside the repository class for an entity.
public function getCarFuels(int $field)
{
return $this->createQueryBuilder('q')
->select('t')
->leftJoin(
'App\Entity\Table',
't',
Join::WITH,
'q.field = t.id'
)
->where('q.field = :field')
->setParameter('field', $field)
->getQuery()
->getArrayResult();
}
This is the equivalent of
SELECT
ft.*
FROM db.first_table q
LEFT JOIN
db.table t on q.field = t.id
WHERE field = n;
Similar blog posts

Elasticsearch cheat sheet
Search Count AND query OR query Query with date range Multiple Queries Or a query inside a query Sort by a date containing field Query with regex Point In Time...
Odroid Sensors
Not long ago I bought an Odroid ARM based mini PC, and among many issues, turned out that the system uses some rather strange scheme for controlling the fan speed....
“Kubernetes network isn’t reliable”
Recently, while trying to figure out an extrelemly annoying problem I was having with Kubernetes – I stumbled upon this marvel of a github issue. So if you ever need...