Re:Today I accept that Rails is yesterday’s software
by pbowyer on Monday May 09, 2016 @04:25PM
(#11662849)
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.
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)