2 ms·
I feel the problem is people go to extremes: either all handmade SQL or all ORM. Mixing both is pragmatic. Take today's example, using the Doctrine2 ORM. I nee
by pbowyer 10y ago
I feel the problem is people go to extremes: either all handmade SQL or all ORM. Mixing both is pragmatic.
Take today's example, using the Doctrine2 ORM. I needed something simple: For every user, find the number of articles belonging to them with a specific status code.
Seems simple. Except the dumb ORM way of count($user->articles) lost the JOIN conditions, and counted every article.
So the 50% way was to use COUNT(article.id) in the query via the ORM. Unfortunately, because it doesn't know where to put the COUNT() value, the ORM destroys the easy usage, and returns a collection of the user object and a scalar value for the COUNT().
I worked with it, but TBH going back to raw SQL in this case would've been much easier.
Pragmatism, the lost art (TM)