Chapters
48 Chapters
|
5:13:28
|
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!
45.
UUID's
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 also works great with API Platform 2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.5.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2.0", // 2.1.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.4.5", // 2.8.2
"nelmio/cors-bundle": "^2.1", // 2.1.0
"nesbot/carbon": "^2.17", // 2.39.1
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", // 5.2.2
"ramsey/uuid-doctrine": "^1.6", // 1.6.0
"symfony/asset": "5.1.*", // v5.1.5
"symfony/console": "5.1.*", // v5.1.5
"symfony/debug-bundle": "5.1.*", // v5.1.5
"symfony/dotenv": "5.1.*", // v5.1.5
"symfony/expression-language": "5.1.*", // v5.1.5
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.5
"symfony/http-client": "5.1.*", // v5.1.5
"symfony/monolog-bundle": "^3.4", // v3.5.0
"symfony/security-bundle": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/validator": "5.1.*", // v5.1.5
"symfony/webpack-encore-bundle": "^1.6", // v1.8.0
"symfony/yaml": "5.1.*" // v5.1.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.3.2
"symfony/browser-kit": "5.1.*", // v5.1.5
"symfony/css-selector": "5.1.*", // v5.1.5
"symfony/maker-bundle": "^1.11", // v1.23.0
"symfony/phpunit-bridge": "5.1.*", // v5.1.5
"symfony/stopwatch": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/web-profiler-bundle": "5.1.*", // v5.1.5
"zenstruck/foundry": "^1.1" // v1.8.0
}
}
8 Comments
Hello there
When I run symfony console doctrine:migrations:migrate I have an error with this message " There is no active transaction" (In Connection.php line 1761:)
I use MySql 5.7 with docker-compose
I use the command : symfony console doctrine:schema:create and it's working.
Hey Stéphane,
I just downloaded a fresh version of this course code and was able to execute migrations successfully in both start/ and finish/ folders. Did you download the course code and started from start/ directory? If so, it sounds like you have a bad migration, please, double-check the migration you created.
And good catch on "doctrine:schema:create" command - if it's a project for learning purposes and you don't care about real data in the DB - that's a totally valid way. For production, you may want to fix your migration otherwise you will lose real data.
Cheers!
Why not use UUID and ULID from Symfony https://symfony.com/blog/ne... ?
And what is the difference between uuids and ulids and which one you encourage to go for? I started a new project and I am using ulids, I havent found alot of docs online.
Hey Zack F. !
> Why not use UUID and ULID from Symfony https://symfony.com/blog/ne... ?
Excellent question! Simply because this tutorial predated that feature... by about 2 months :). It was actually introduced already by the time we recorded this (so I knew about it), but it wasn't released stable yet. I mention this here - https://symfonycasts.com/sc... - but overall, it shouldn't make any difference, except that (maybe) using the Symfony UUID component will be even easier to integrate (though using ramsey is also pretty easy).
> And what is the difference between uuids and ulids and which one you encourage to go for
To be honest, I don't know much about these. But from some quick looking, it seems to me like, in practice, ULIDs are... a more awesome version of UUIDs. A ULID might be less random (as they have the created time encoded + are sortable)... but, unless the "created time" is sensitive to be shared publicly, that's kind of an awesome feature! And so is "sortability" - it's kind of nice to be able to sort database records by ULID and have them be in order. So honestly... yea... go for ULIDs! they're also prettier as URLs ;). I don't see any real disadvantage to them.
Cheers!
Hi, I´ve been trying to use the new Symfony UID, but having trouble on the Doctrine Type as the doctrine migration tries to create an BINARY(16) column instead of CHAR(36) as on the video. I´m using MySQL.
Is there a way to update symfony uuid type to use char(36) or it is better to just use the Ramsey as in the course.
Hey Erico Vasconcelos!
I don't know too much about this, but the Symfony version is definitely made to use a REAL UUID type (if your database supports it, which I believe MySQL does not) else it ALWAYS uses binary. Binary is more of a pain to deal with, but it's more efficient, which is why Symfony chose to only offer that. So if you want to use MySQL and want the string representation, then stick with ramsey :). But know that there could be some performance issues (these are often overblown, but it could be a real problem).
Cheers!
Hi Ryan,
For the benefit of creating uuid from client side, I cannot actually see that since most of the time the client still need to wait for the API response to ensure the resource actually is created before they can do some extra jobs. Can you pleas give me some real world examples?
Thanks!
Hey Tuan Vu !
Very good question. And, I think this "advantage" is less common than I originally thought, but it does come in handy sometimes. Here's an example. Suppose you have a list of... products on a page. At the bottom of the list, you have an "add new product" button. When you click that, it instantly adds a new row to the table that renders the new product data (probably with blank or dummy values to start). It also "rolls out" a form on the sidebar with the product fields. As you type into those fields, the new row at the bottom of the table fills in with the new data automatically.
In this situation, if you're using something like React or Vue, you likely have some "products" state/data, which you're looping over to create the rows in the table. When you click "add new product", in order to add the new row immediately (even before saving), you'll add a new item to the "products" data. That will new item will need to have a unique key. You *could* create a fake key, then update it after you save (and get the new id), but it's not as smooth and it would actually cause Vue/React to re-render that row like new item.
So, in short, you need to have a situation where you're already rendering an item even *before* it's saved. It's not the normal situation, but hopefully that answers your question :).
Cheers!
"Houston: no signs of life"
Start the conversation!