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
}
}
6 Comments
Hi,
I am struggling with the custom many to many relationship. Maybe it is because of the 'friendship relation' instead of between two different entities. In my case a user can have 2 type of friendships. 1 is having a client: the user can help the client in my project. But a Client can have an Admin-like friend, the user who is helping the client.
Below first the User Entity class:
And the UserClient Entity:
After login I get the active user by:
But I never get the relations, if I use dd($activeUser), I get this:
I dont know what I am doing wrong, but trying to get the client with the getClient(), is always empty.
Hey @Bart-V
Could you double-check that your database schema is correct and the records are saved? From the dump you shared, I see a property that's not in your User class, the
AuthGroupproperty, and that one is holding the other two relationships. Do you see the same, or did the formatting confuse me?Cheers!
Yes i have a property AuthGroup. I did erase some field, otherwise the message would be giant.
And i tried the many to many, build with the makerbundle. And a custom version. Both give empty when calling the method getClients().
I cannot find alot about a many to many friendship relation, so i am strugling.
I just noticed that your relationships between User and UserClient are
OneToManyandManyToOne. You would need to change it toManyToManyor introduce an extra entity in between to link both sides (it's like handling theManyToManyby yourself)Cheers!
Hi,
I deleted everything from the user-user relationship and started from the beginning again. I used the makerbundle again and i found the next code in the documentation:
With the makerbundle the ORM jointable, joincolumn etc is not added. So i added those lines, and it works.
You can find it here: doctine many-to-many self-referencing
Nice research, I think MakerBundle does not add those lines because it doesn't know you're adding a self-referencing property.
Well done anyway, cheers!
"Houston: no signs of life"
Start the conversation!