Chapters
41 Chapters
|
4:45:40
|
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!
17.
Agree to Terms Database Field
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.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"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.8.0
"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
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
16 Comments
Very good video! I just wanted to add something that developers might come across in their own projects. In my projects at least I usually already have a
createdAtproperty on my user entities. In that case, you do not need theagreedTermsAtproperty as I can use the former property. (well, maybe you need to consult your lawyer for that again, but it seems excessive to have two columns that are identical)Anyways, all of the points raised in this video still hold up, and I like how it explains how to migrate a non-nullable property in detail.
Hey Robin,
Thank you for your feedback! We're happy your found this video useful for your :)
About reusing the createdAt field - hm, technically yes, but that is something that would be good to check with the layer :) I think, you can just rename that "createdAt" field into "agreedTermsAt" and it will be perfect this way. Because createdAt isn't clear enough from the perspective of agreeing terms - I think the main idea is to have the clear name for this just in case, but I'm not sure 100% here. Also, technically, you may have 2 getters that e.g. getCreatedAt() and getAgreedTermsAt() that both links to the same field called in the DB - probably in code it will have more sense.
P.S. though even having 2 columns in the DB that will hold same data isn't a big deal in this case, so you can just close your eyes on it ;)
Cheers!
interesting how you do with not nullable values. In our team we just allow null values for new columns even if they never should be null by business logic, just because we do not know what value to set on existing fields. Is that a bad thing?
Hey Lijana Z.
In my opinion it can be a bad thing because your application may have a bug where you forgot to set a field's value or something like that, and you won't notice it because your Database will allow it
Adding a new field to an already populated table some times is not easy to know which default value you should put in but based on what I said above I think it worth the effort of thinking in a "good enough" default value
Cheers!
This is the example of forms when you need unexpected behaviour like this and feeling like "how the hell now I will do this with symfonny forms" :)
Haha, I couldn't agree more :). That's why I think this "mapped => false" thing is so important: it's a "Swiss Army Knife" that can help with many of these situations.
Cheers!
general question if I may,
why datetime instead of timestamp? in real app you would have some nice JS calendar to pick a date/time, which then can be converter into timestamp right?
Hey Jakub G.
Doctrine doesn't come with a "timestamp" field type but AFAIK you can use a Datetime field as if it were a Timestamp field
I hope it makes any sense to you :)
Cheers!
3:45 you do not have to implement any fix in mysql 8+
Malnet
What you mean? In MySql8 if a migration with multiple statements fails, it rolls back?
Working with MariaDB avoid getting the error but the
agreed_terms_atfield has a0000-00-00 00:00:00value applied.About the "rollback" idea of "smarter RDBMS", wouldn't using transactions solve the issue (not an expert about that, just wondering) ? Or maybe Doctrine has something similar to transactions (what's the
downmethod for ?) ?Hey AymDev
Cheers!
Had no errors on the first migration, probably because of MariaDB:
Hey Ivan,
Thank for proving that it works great with MariaDB! Glad to hear it.
Cheers!
Did you have to generate 2 migration files?
why not just to add 3 statements
$this->addSQL('...DEFAULT NULL..');
$this->addSQL('...UPDATE USERS..');
$this->addSQL('...NOT NULL..');
Hey Peter K.!
Yep - that's 100% valid. I was mostly being lazy... - after running the first file, the second one is generated for me automatically (instead of me writing it manually) :)
Cheers!
"Houston: no signs of life"
Start the conversation!