Chapters
27 Chapters
|
2:45:18
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
09.
Relation OrderBy & fetch=EXTRA_LAZY
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
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.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.3", // v3.3.0
"composer/package-versions-deprecated": "^1.11", // 1.11.99.3
"doctrine/doctrine-bundle": "^2.1", // 2.4.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.1.1
"doctrine/orm": "^2.7", // 2.9.5
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.1
"pagerfanta/doctrine-orm-adapter": "^3.3", // v3.3.0
"pagerfanta/twig": "^3.3", // v3.3.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"stof/doctrine-extensions-bundle": "^1.4", // v1.6.0
"symfony/asset": "5.3.*", // v5.3.4
"symfony/console": "5.3.*", // v5.3.7
"symfony/dotenv": "5.3.*", // v5.3.7
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.3.*", // v5.3.7
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/runtime": "5.3.*", // v5.3.4
"symfony/stopwatch": "5.3.*", // v5.3.4
"symfony/twig-bundle": "5.3.*", // v5.3.4
"symfony/validator": "5.3.*", // v5.3.14
"symfony/webpack-encore-bundle": "^1.7", // v1.12.0
"symfony/yaml": "5.3.*", // v5.3.6
"twig/extra-bundle": "^2.12|^3.0", // v3.3.1
"twig/string-extra": "^3.3", // v3.3.1
"twig/twig": "^2.12|^3.0" // v3.3.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.3.*", // v5.3.4
"symfony/maker-bundle": "^1.15", // v1.33.0
"symfony/var-dumper": "5.3.*", // v5.3.7
"symfony/web-profiler-bundle": "5.3.*", // v5.3.5
"zenstruck/foundry": "^1.1" // v1.13.1
}
}
10 Comments
Hey,
How to obtain the same effect with
@ORM\OrderBy({"createdAt" = "DESC"})in PHP8?When I am using
#[ORM\OrderBy(createdAt: 'DESC')]it causes an error -Unknown named parameter 'createdAt'Hey Szymon,
I'm afraid you forgot to import the
TimestampableEntitytrait in your class. Let me know if that helpsCheers!
Hello MolloKhan,
Of course I have it in my Question class. I think problem is with
#[ORM\OrderBy(createdAt: 'DESC')]syntax.I have tried a lot of combinations but can't figure out what is the case.
Oh, I think this is the syntax you need
#[ORM\OrderBy(['createdAt' => 'DESC'])]This Code write you
`class AppFixtures extends Fixture
{
}`
But a few episodes ago u use this shortcut
class AppFixtures<br /> AnswerFactory::createMany(100);this shortcutis good for this epidose I think
class AppFixtures<br /> AnswerFactory::createMany(100);<br /> AnswerFactory::new()->needsApproval()->many(20)->create();<br />Cheers!
As I understood this chapter, TWIG triggers SQL-Queries, in other word, TWIG initiates additional DB-connections. Really? Until now I thought, only the controller (& services) triggers the SQL-queries via Doctrine and passes the results to TWIG via the return-array, so TWIG just could use what the controller already produced. Now which is correct?
Hey Planschkuh1992,
Yes, that's right. With ORM thing a bit more complicated, because you can query from the DB for example a user object, then pass it to the template, where you will call "user.getOrders()" and iterate over user's orders to list them. Doctrine may not load those orders initially for performance reason when you fetch the object from the DB, because probably you will never need that data. But on the explicit request of those data that happened in the template, additional queries might be sent to the DB to fetch that extra information. And it's kinda OK, because first of all, that's handled by third-party logic of that ORM, it's not about you sending a DB query directly from the template, right? it's happening behind the scene. But if you got access to the DB connection in the template and wrote a query that will hit the DB from inside the template - it would be a bad practice for sure.
That's just one example. I hope it clarify things for you.
Cheers!
are we just going to live with the N+1 problem? ....oops sorry my bad. I see we will get to that in Chapter 14.
Haha, no problem. And yes, often I DO just live with the N+1 problem anyways... Blackfire is great for showing me when that's *actually* a problem :).
Cheers!
What?? I am a bit too obsessive-compulsive for that :-) seriously though --- I have created an ambitious Doctrine project and it works brilliantly, but there were a few spots where I never did figure out how to cut the queries down to as few as I believed they should be, and a lot of hoop-jumping to fix N+1. Part of my motivation for being here is to learn Doctrine better -- iow to get more inDoctrinated.
"Houston: no signs of life"
Start the conversation!