Customizing the User Class
…roles and first_name columns.
Close this... and run it:
symfony console doctrine:migrations:migrate
Success!
And because the User entity is... just a normal Doctrine entity, we can also
add dummy users to our database using the fixtures system.
Open up src/DataFixtures/AppFixtures…
Verify Email after Registration
…migration:
symfony console make:migration
Go check that out and... awesome. It looks exactly like we expect:
Run it!
symfony console doctrine:migrations:migrate
Beautiful! Let's do one more thing related to the database. Inside of
src/Factory/UserFactory.php, to make life simpler…
Giving Users Passwords
…sure everything looks good:
And... it does! Close it... and run it:
symfony console doctrine:migrations:migrate
Perfect! Now that our users have a new password column in the database, let's
populate that in our fixtures. Open up src/Factory/UserFactory.php and
find…
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…
Joins and addSelect Reduce Queries
…That's different from SQL, where selecting all
the fields from a joined table will give you more fields in your result.
Here, addSelect() just tells Doctrine to fetch the FortuneCookie data,
but store it internally. Later, when we access the FortuneCookies for a
Category…
Symfony: Keep it Simple with @Route and Templates
…
So let’s finish this page. It should be fairly straightforward: we’re going
to use Doctrine to query for all the posts and then pass them into a template:
/**
@Route("/posts")
/
public function indexAction()
{
}
Now, notice that my template name does not have any…
Testing with Multiple Symfony Versions
…In our composer.json file, for the Symfony
packages, this means 6.4.0. For the doctrine-bundle, it would be 2.18.0.
To get these lowest versions installed, over in the terminal, run:
symfony composer update --prefer-lowest
We can see Composer switched…
Warmup Command Configuration
…the parent class if we detect that it's a proxy.
After creating the ReflectionClass, write if ($class->implementsInterface(Proxy::class)).
Import the class from Doctrine\Persistence:
All generated proxies have this interface.
Inside, write $class = $class->getParentClass() to get the true entity class:
…
Writing an Integrational Test for Webhooks
…an error, but that's expected.
No such table in the test environment.
Our test is failing because we need to set up a test database. We
could do this manually using Doctrine console commands, but let's take
advantage of Zenstruck Foundry, which we…
Auto Setting the "owner"
…for this: the state processor system.
As a reminder, our POST and PATCH endpoints for DragonTreasure already have a state
processor that comes from Doctrine: it's responsible for saving the object to
the database. Our goal will feel familiar at this point: to decorate…
Totally Custom Fields
…is loaded. For
example, our classes are already using a Doctrine state provider behind the
scenes to query the database. We'll cover state providers in part 3 of this series.
The second solution would be to use the custom normalizer like we did, then…
Adding new Properties
…anything in my
database? The answer is no. I can prove it by running a helpful command:
symfony console doctrine:schema:update --dump-sql
This is very similar to the make:migration command... but instead of generating
a file with the SQL, it just prints…
Recipe Upgrades with recipes:update
…the recipe relate to the config files, and I bet you can see
what's happening. It deleted two environment-specific config files and updated
the main one. Hmm.
Open config/packages/doctrine.yaml. Sure enough, at the bottom, we see when@test
and when…
Dynamic Roles
…paste, use abraca_user@example.com... and leave roles empty:
Let's do it! At your terminal, run:
symfony console doctrine:fixtures:load
When that finishes... spin over and refresh. We got logged out! That's because, when
the user was loaded from the session…
Custom Repository Class
…here.
We'll see this idea of custom entity methods later.
At the bottom, there's one more link: question.slug.
Done! Doctrine makes it easy to query for data and Twig makes it easy to render.
Go team! At the browser, refresh and... cool…
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…
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…
Dummies
…object - an object that does work, but doesn't hold much data, like
DinosaurFactory, Doctrine's EntityManager or a class that sends emails, mock
it. That's because these are usually difficult to instantiate and often have side
effects, like talking to the database or…
Let: The Setup Function
…If you're a Doctrine user, this will look familiar. But, no, I'm not recommending
that you actually create or move the EntityManagerInterface into your app like
this. We're adding this interface as a convenient way to "pretend" like Doctrine
exists in our…
x
1000+