Chapters
24 Chapters
|
1:14:57
|
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!
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.
This tutorial works perfectly with both Symfony 7 & 8!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^4.5", // v4.5.0
"doctrine/dbal": "^4", // 4.2.3
"doctrine/doctrine-bundle": "^2.13", // 2.14.0
"doctrine/doctrine-migrations-bundle": "^3.3", // 3.4.1
"doctrine/orm": "^3.3", // 3.3.2
"knplabs/knp-time-bundle": "^2.2", // v2.4.0
"pagerfanta/doctrine-orm-adapter": "^4.7", // v4.7.1
"php-cs-fixer/shim": "^3.46", // v3.73.1
"phpdocumentor/reflection-docblock": "^5.3", // 5.6.1
"phpstan/phpdoc-parser": "^2.0", // 2.1.0
"stof/doctrine-extensions-bundle": "^1.12", // v1.13.0
"symfony/asset": "7.2.*", // v7.2.0
"symfony/asset-mapper": "7.2.*", // v7.2.3
"symfony/console": "7.2.*", // v7.2.1
"symfony/dotenv": "7.2.*", // v7.2.0
"symfony/flex": "^2", // v2.5.0
"symfony/framework-bundle": "7.2.*", // v7.2.4
"symfony/http-client": "7.2.*", // v7.2.4
"symfony/monolog-bundle": "^3.0", // v3.10.0
"symfony/property-access": "7.2.*", // v7.2.3
"symfony/property-info": "7.2.*", // v7.2.3
"symfony/runtime": "7.2.*", // v7.2.3
"symfony/serializer": "7.2.*", // v7.2.4
"symfony/stimulus-bundle": "^2.13", // v2.23.0
"symfony/twig-bundle": "7.2.*", // v7.2.0
"symfony/ux-turbo": "^2.13", // v2.23.0
"symfony/yaml": "7.2.*", // v7.2.3
"symfonycasts/tailwind-bundle": "^0.9.0", // v0.9.0
"twig/extra-bundle": "^2.12|^3.0", // v3.20.0
"twig/twig": "^2.12|^3.0" // v3.20.0
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^4.0", // 4.0.0
"symfony/debug-bundle": "7.2.*", // v7.2.0
"symfony/maker-bundle": "^1.52", // v1.62.1
"symfony/stopwatch": "7.2.*", // v7.2.4
"symfony/web-profiler-bundle": "7.2.*", // v7.2.4
"zenstruck/foundry": "^2.2" // v2.3.8
}
}
11 Comments
Hi,
I also only got a single row with the groupBy, I had to add COUNT(droid) AS HIDDEN droidCount in the select.
Hey @Cedric
I just gave it a try, and the query works well. I'm confused why adding a select changes the number of fetched rows. Did you download the course code from this page or are you coding it from scratch?
Cheers!
Hi @MolloKhan,
Thanks for your quick reply. I just tried again by mounting the Docker container with the Postgres database, and everything works.
I was using a local MariaDB database during the course.
Ohh that makes sense. I'm glad you found a solution. Cheers!
Hello! Loving this course. When I use a mysql database I get this error after updating the findIncompleteOrderedByDroidCount() function
An exception has been thrown during the rendering of a template ("An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #10 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'starshop2.s1_.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by").Tried a few things to fix it but I'm coming up blank. Thanks!Hey @Logan-M
We're glad to hear you're liking our content. Can I see your query/code?
Cheers!
Here is my code below. The only difference I notice is the use statement for starshipStatusEnum (Mine is in a different location). I am using a MySQL database not the PostgreSQL.
`<?php
namespace App\Repository;
use App\Entity\Starship;
use App\Model\StarshipStatusEnum;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
/**
*/
class StarshipRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
}
/**
*/
public function findIncompleteOrderedByDroidCount(): Pagerfanta
{
$query = $this->createQueryBuilder('s')
;
return new Pagerfanta(new QueryAdapter($query));
}
public function findMyShip(): Starship
{
return $this->findAll()[0];
}
// /**
// @return Starship[] Returns an array of Starship objects // /
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Starship
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
`
The raw query looks like this:
SELECT s0_.id AS id_0, s0_.name AS name_1, s0_.captain AS captain_2, s0_.class AS class_3, s0_.status AS status_4, s0_.arrived_at AS arrived_at_5, s0_.slug AS slug_6, s0_.created_at AS created_at_7, s0_.updated_at AS updated_at_8 FROM starship s0_ LEFT JOIN starship_droid s2_ ON s0_.id = s2_.starship_id LEFT JOIN droid d1_ ON d1_.id = s2_.droid_id WHERE s0_.status <> ? GROUP BY s0_.id ORDER BY COUNT(d1_.id) ASCThanks for taking the time to look at this.
Hey @Logan-M!
Ah, in recent versions of MySQL, GROUP BY is more strict than Postgres. Basically, you can't do dynamic operations like we're doing in
->orderBy()- it needs to be a column.Take a look at this comment above for, I think, the solution - this should work in MySQL and Postgres.
I hope this helps!
Kevin
Thanks! That makes sense.
In the last step, PagerFanta doesn't work. I only see one ship and 14 pages.
Hey @giorgiocba
I just gave this a try (with the new code) and it works fine. Could you copy-paste the AppFixtures code from this code block and try again?
https://symfonycasts.com/screencast/doctrine-relations/many-to-many-foundry#codeblock-3d67ea2ef7
Cheers!
"Houston: no signs of life"
Start the conversation!