Chapters
29 Chapters
|
3:14:24
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
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!
18.
DoctrineBundle Updates & Recipe Upgrade
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": "^7.3.0",
"ext-iconv": "*",
"antishov/doctrine-extensions-bundle": "^1.4", // v1.4.2
"aws/aws-sdk-php": "^3.87", // 3.110.11
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.1
"doctrine/doctrine-bundle": "^2.0", // 2.0.6
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // 2.1.2
"doctrine/orm": "^2.5.11", // v2.7.2
"doctrine/persistence": "^1.3.7", // 1.3.8
"easycorp/easy-log-handler": "^1.0", // v1.0.9
"http-interop/http-factory-guzzle": "^1.0", // 1.0.0
"knplabs/knp-markdown-bundle": "^1.7", // 1.8.1
"knplabs/knp-paginator-bundle": "^5.0", // v5.0.0
"knplabs/knp-snappy-bundle": "^1.6", // v1.7.0
"knplabs/knp-time-bundle": "^1.8", // v1.11.0
"league/flysystem-aws-s3-v3": "^1.0", // 1.0.23
"league/flysystem-cached-adapter": "^1.0", // 1.0.9
"league/html-to-markdown": "^4.8", // 4.8.2
"liip/imagine-bundle": "^2.1", // 2.3.0
"nexylan/slack-bundle": "^2.1", // v2.2.1
"oneup/flysystem-bundle": "^3.0", // 3.3.0
"php-http/guzzle6-adapter": "^2.0", // v2.0.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.4
"sensio/framework-extra-bundle": "^5.1", // v5.5.3
"symfony/asset": "5.0.*", // v5.0.2
"symfony/console": "5.0.*", // v5.0.2
"symfony/dotenv": "5.0.*", // v5.0.2
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "5.0.*", // v5.0.2
"symfony/framework-bundle": "5.0.*", // v5.0.2
"symfony/mailer": "5.0.*", // v5.0.2
"symfony/messenger": "5.0.*", // v5.0.2
"symfony/monolog-bundle": "^3.5", // v3.5.0
"symfony/property-access": "4.4.*|5.0.*", // v5.0.2
"symfony/property-info": "4.4.*|5.0.*", // v5.0.2
"symfony/security-bundle": "5.0.*", // v5.0.2
"symfony/sendgrid-mailer": "5.0.*", // v5.0.2
"symfony/serializer": "4.4.*|5.0.*", // v5.0.2
"symfony/twig-bundle": "5.0.*", // v5.0.2
"symfony/validator": "5.0.*", // v5.0.2
"symfony/webpack-encore-bundle": "^1.4", // v1.7.2
"symfony/yaml": "5.0.*", // v5.0.2
"twig/cssinliner-extra": "^2.12", // v2.12.0
"twig/extensions": "^1.5", // v1.5.4
"twig/extra-bundle": "^2.12|^3.0", // v3.0.1
"twig/inky-extra": "^2.12", // v2.12.0
"twig/twig": "^2.12|^3.0" // v2.14.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.3.0
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/browser-kit": "5.0.*", // v5.0.2
"symfony/debug-bundle": "5.0.*", // v5.0.2
"symfony/maker-bundle": "^1.0", // v1.14.3
"symfony/phpunit-bridge": "5.0.*", // v5.0.2
"symfony/stopwatch": "4.4.*|5.0.*", // v5.0.2
"symfony/var-dumper": "5.0.*", // v5.0.2
"symfony/web-profiler-bundle": "4.4.*|5.0.*" // v5.0.2
}
}
11 Comments
Hi, I ran into some trouble with my entities after moving to symfony 5 (5.4). I while back (already in sym 4 possibly) we were instructed to reference our entities with a "::class" at the end in the getRepository() function. I had nested my Entities to keep them cleaner in the directory structure and therefore opted to keep my way of referencing them (as it still worked back then). My directory structure looks like this
I currently do this when I pick up an entity
$analyses = $em->getRepository('App:Hazardlog\Analysis')->findAll();That no longer works. I've tried all three of these with no luck:
Is there no longer a way to keep my entities neatly organized into folders? Or is there a trick to referencing them?
Hokey, I figured out that I could to this instead:
Hey Matt,
Awesome, I'm happy you were able to figure it out yourself, well done!
Btw, you were very close in your 3rd try, i.e. the option with
$analyses = $em->getRepository('Analysis::class')->findAll();is almost correct, but it should be this way:I.e. It should not be in quotes ;)
Cheers!
Hi, apparently my mySql is a MariaDB, for server version phpMyAdmin says <b>10.3.35-MariaDB-log - FreeBSD ports</b> so should my doctrine.yaml then look like this?
Hey Mattias,
Good question! Well, it should look like "server_version: 'mariadb-10.3.35'", i.e. you should add that "mariadb-" prefix for MariaDB SQL servers - that's a standard you should just follow :)
But keep in mind that it's better to write there the version you have on production. And ideally, you should have the same version locally and on production so that it works without problems. Otherwise, you can try to specify the lowest version from both and see if it will work well. Otherwise, you would need to specify that version different for different environment using .env files.
I hope this helps!
Cheers!
Thank you! Yes, that was from the production server. But oh, I just realized that I have MariaDB in production, but for my local server I'm running <b>"Server version: 5.7.32 - MySQL Community Server (GPL)"</b> so they are completely different then I suppose.
So one way would be to put the respective versions in the DB connection strings.
I suppose another way would be to put a doctrine.yaml file in each of the config/packages/prod and config/packages/dev directories, and put this in the config/packages/dev/doctrine.yaml
Hey Mattias,
Hm, well, they are not that much different fairly speaking.. but yeah, it's better to separate them. The more specific version you specify there - less problems you will have, and queries that Doctrine generates in migrations will be more optimized for too. But I used to have MariaDB on prod and MySQL locally and it works OK with the MariaDB server_version for me. So, it depends.
> I suppose another way would be to put a doctrine.yaml file in each of the config/packages/prod and config/packages/dev directories, and put this in the config/packages/dev/doctrine.yaml
Well, it might be enough for you, but it's not quite correct IMO, because you may load your project in prod mode locally... and what then? The website will use MariaDB version locally? If you never do this - probably it will be OK, at least this strategy is simple. But keep in mind that if you will generate a migration in dev mode - it will use MySQL version instead of MariaDB, but the problem that you want to use MariaDB as you need to run that migration on prod.
A better would be to create an env var in .env files and set it to MySQL version locally and to MariaDB version on prod- this should be the correct way to solve this.
But ideally, install and start using MariaDB locally too :)
> server_version: 'mysql-5.7.32'
Haha, uh oh, almost like that :) With MySQL it's simplified to just "5.7.32", you can see more config options here in the docs: https://symfony.com/doc/cur... . As you can see, MariaDB complicates that value a bit, but it's simple with MySQL. Actually, it's difficult to remember, so I usually look at the docs when I need to configure it.
Cheers!
Hello, when i saw the naming strategy changed in the doctrine.yaml
file i got scared ! When i dump the sql for the schema:update cmd, i see
a lot of changes regarding some tables. Thing is i have a lot of
relations in there, so if i actually udpate my database schema, it
breaks because of foreign keys. What can i do about that ? I do not want
to loose my data, and my database has a lot of tables !
Hey @elbarto
You can choose whatever naming strategy is convenient for you, or you can create your own strategy in case you need to. Check line 298 https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html
I believe the
CamelCaseNamingStrategyis set by default, you can change it to use theUnderscoreNamingStrategyI hope it helps. Cheers!
Hello Diego,
If i put back doctrine.orm.naming_strategy.underscore in my doctrine.yaml file, i then get a deprecation message : User Deprecated: Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.
The thing is, what solutions do we have if i want to pass from underscore to underscore_number_aware strategy and updating my database. Because as i said earlier, if i have few tables named table1_test , table2_test. They will become table_1_test and table_2_test.
On a schema:update it breaks because i have a bunch of relations (FK) inside of them, thus forbidding me to update my schema.
Thanks in advance !
Hmm, you can ignore that deprecation :D
or, another solution is to manually define the name of all the tables you have problems with
The naming strategy is only used when Doctrine have to give it a name to your tables/fields
Cheers!
"Houston: no signs of life"
Start the conversation!