The course is built on Symfony 4, but the principles still apply perfectly to Symfony 5 - not a lot has changed in the world of relations!
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.7.2
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0", // v4.0.14
"twig/extensions": "^1.5" // v1.5.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
3 Comments
Hi, I wanna start by saying that I really enjoy this series and the way you teach.
Now, I come from a no-framework background and I would build all my queries by hand.
I absolutely want to start using Symfony, but the way it handles the database is very confusing and strange for me because I am used to build and control all my queries.
For example, I don't know if this will be covered in the next videos, but I wanted to know how to eliminate the 5 extra queries to count the comments on the home page. Is true that with EXTRA_LAZY is a little faster than just getting all comments for each article, but you still make a query for each article.
If I were to build this page how I do normally, I would just join the articles to the comments table when fetching all articles, and do a count on the joined comments table, so the number of comments of each article will be a field/property on each article and there will only be one query on the home page.
So my question is, can we control the fetch all articles method to do this, or I have to build a custom method and use that for fetching articles?
Thank you.
How can I sort articles in table by comments column which is @OneToMany relation in articles entity with knp_pagination_sortable by their count for each article? I tried adding a.comments as third argument in knp_pagination_sortable, but it doesn’t work.
Hey Nikolay S.
That's an interesting question. I think what you can do is to add a
left jointo comments, then, add a countCOUNT(article.comments) as totalCommentsand then and anorder byby that field. I'm not sure if it will work with the paginator but that's where I'd startCheers!
"Houston: no signs of life"
Start the conversation!