Wall Time, Exclusive Time & Other Wonders
…whatever that is. If you use Doctrine,
you might know what this is - but let's pretend we have no idea.
Before we dive further into the root cause behind this slow function, the
other way to order the calls is by the number of…
Using the Filesystem
…that: article_image/ and then $newFilename.
I think we're ready! Let's clear out the uploads/ directory again. And then
try our fixtures:
php bin/console doctrine:fixtures:load
Oh! It does not work!
Unused binding $uploadsPath in service UniqueUserValidator.
This is a bad…
Reordering the Files
…the usual:
php bin/console make:migration
and go to the src/Migrations directory so we can make sure it doesn't contain
any surprises. Looks perfect! Close that and run:
php bin/console doctrine:migrations:migrate
Ok, the database is ready! For the frontend…
Deleting Files
…problem:
the file might get deleted, but then the row stays because of a temporary connection
error to the database.
If you're worried about this, use a Doctrine transaction to wrap all of this
logic. If the file was successfully deleted, commit the transaction…
Setup for Uploading Private Article References
…yep!
CREATE TABLE article_reference
... with a foreign key back to article. Run that with:
php bin/console doctrine:migrations:migrate
Before we get back to work, open the Article entity. The command did create
the $articleReferences property that allows us to say
$article->getArticleReferences()…
File Upload Field in a Form
…will not work. Pretty commonly,
you'll see people create this property on their entity, just to make the form
work. They don't persist this property to the database with Doctrine... so the idea
works, but I don't love it.
Instead, we'll…
Triaging a Bug Issue
…the user says that he got an error when trying to serialize a Doctrine
QueryBuilder with the web profiler: something about not being able to serialize
a PDO instance.
The web profiler works by collecting a bunch of information about the request
and serializing it…
Linking Symfony deps to your Local Copy
…to use annotations with the
validator, you need to install the annotations library. Stop the web server and
run:
composer require annotations
This installs sensio/framework-extra-bundle... we only technically need
to install doctrine/annotations. But, that's ok. Restart the built-in web…
Flex Extras
…more going on. Find your composer.json file and make sure
the version constraint is ^3.0.
Then, run:
composer update doctrine/doctrine-fixtures-bundle
Version 3 of this bundle is all new... but not in a "broke everything" kind of
way. Before, fixture classes…
Bye Bye AppBundle
…But, the fix is easy: Find all
AppBundle and replace with App.
Done! There is one last thing we need to undo: in config/packages/doctrine.yaml.
Remove the AppBundle mapping we added.
So, what other AppBundle things haven't been updated yet? It's…
Final config/ Migration
…We can also delete config_prod.yml.
Oh, by the way, if you have some doctrine caching config in config_prod.yml,
I would recommend not migrating it. The DoctrineBundle recipe gives you prod
configuration that is great for production out-of-the-box. Booya…
Priming cache.app
…production. Add framework, cache and app set to cache.adapter.redis:
cache.adapter.redis is the id of a service that Symfony automatically makes
available. You can also use cache.adapter.filesystem - which is the default -
doctrine, apcu, memcached or create your own service. If…
Safe Migrations
…back a deploy before. But, let's update it to be safe: SET image = poster, and
then ALTER TABLE to drop poster:
This is a safe migration. First, try it locally:
./bin/console doctrine:migrations:migrate
Perfect! And now... deploy! Right? No! Stop that…
Autowiring Deprecations
…we can create an alias.
Copy the Doctrine\ORM\EntityManager class name. Then, find your editor and open
up services.yml. Add the alias: Doctrine\ORM\EntityManager aliased to @,
and then copy the target service id: @doctrine.orm.default_entity_manager:
We have full control…
Autowiring Controller Arguments
…container directly! We know the fix: type-hint a new argument with
LoginFormAuthenticator $authenticator and use that below:
Almost done! The app.doctrine.hash_password_listener service isn't being used anywhere,
and neither is app.form.help_form_extension.
And... that's it! At…
_defaults, autowire & autoconfigure
…it for you.
This works for many - but not all tags. It does not work for doctrine.event_subscriber
or form.type_extension:
Because it has an extended_type tag option... which the system can't guess for you.
When you're developing a feature…
Adding to a Collection: Cascade Persist
…operations for GenusScientist.
Umm, what? Here's what's going on: when we persist the Genus, Doctrine sees the
new GenusScientist on the genusScientists array... and notices that we have
not called persist on it. This error basically says:
Yo! You told me that you…
Collection Delete & allow_delete
…submit, the final array will have
three GenusScientist objects in it, instead of four.
Ready? Submit!
Hmm, no error... but it still doesn't work. Why not? Hint: we already know the
answer... and it relates to Doctrine's inverse relationships. Let's fix it.
Saving the Inverse Side of a ManyToMany
… What's going on!?
This is the moment where someone who doesn't know what we're about to learn,
starts to hate Doctrine relations.
Earlier, we talked about how every relationship has two sides. You can start with
a Genus and talk about the…
EntityType Checkboxes with ManyToMany
…to change the genusScientists property, that's what we should call the field.
The type will be EntityType:
This is your go-to field type whenever you're working on a field that is mapped as any
of the Doctrine relations. We used it earlier…
x
1000+