06.
SELECT the SUM (or COUNT)
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
13 Comments
Hi, I like the tutorial, very straight forward.
One question - do you have to actually create a new migration and add this new numberPrinted field to your physical database?
Hey brentheigold
Migrations are for updating your DB schema, so, whenever you have to add a new field, a new table or updating an existing field you should generate a migration for it
Cheers!
very interesting tutorial can i ask question how to addapt this tutorial into let say querying to count total_price? thank you
Hey Lavin Bassam
If you need to do a "COUNT" operation, then you only have to change the "SUM" statement by a "COUNT", select the right field, and that's it.
Cheers!
how can put a count number beside the checkboxes retrieved from an Entity class
Hey @mike
Can you elaborate a bit more your question. I don't fully understand what you mean
Hello,
About that getSingleScalarResult method :
What if there is no entity persisted at all in the first place ?
Will the method call raise an error / throw an exception ?
Hey Mykel Chang
That's correct!
If the query doesn't return a result it throws, or if it returns more than one result it throws too
Cheers!
Hey, why you skip getManager() part in controller when you were writing scalar type result.
Ok, EntityManager is only needed when you want to save data tego database. No need this guy when fetching data.
Hey Dominik,
Yes, getManager() return EntityManager instance which basically need when you want persist() an entity or flush() persisted ones.
Cheers!
Hey,
The use of alias into select('SUM(fc.numberPrinted) as fortunesPrinted') is not mandatory ? If you don't write the query works.
Hey Stéphane,
You're right, field alias is optional here. But if you missing this alias, the field name should be "SUM(fc.numberPrinted)" but "fortunesPrinted". So in this case you have to use $fortunesPrinted['SUM(fc.numberPrinted)'].
Cheers!
"Houston: no signs of life"
Start the conversation!