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…
Translation Logic
…and run:
symfony console debug:autowiring ManagerRegistry
Here we go: alias:doctrine - doctrine is the service ID - that's a short one!
Copy that and back in services.php, define it as the fourth argument:
service(), paste:
Perfect!
Doctrine's now available in our ObjectTranslator…
Dynamic Data
… Up here, we can add a description:
Add a column to store the LS variant ID on Product.
Back in our terminal, run the migration with:
bin/console doctrine:migrations:migrate
Now, in src/DataFixtures/AppFixtures.php, set our new field to the variant ID…
Writable Collection via the PropertyAccessor
…into why we can't have a setter, but it relates to the
fact that we need to set the owning side of the Doctrine relationship. We talk
about this in our Doctrine relations tutorial.
The point is, if we were able to just call…
Quick! Create a DragonTreasure DTO
…And finally, remove the custom
DragonTreasureStateProvider and DragonTreasureStateProcessor classes.
But we did keep one thing: DragonTreasureIsPublishedExtension. Because the
new system will still use the core Doctrine CollectionProvider, this query
extension stuff will continue to work and be called. That's just one less
thing we…
Validating how Values Change
…what they originally looked like.
So, we are going to solve this with validation... but with the help of a special
class from Doctrine called the UnitOfWork.
Alrighty, let's whip up a test to shine a light on this pesky bug. Inside
tests/Functional/…
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…
Handling Messages Sync while Developing
…And... yea! Because we're currently in the dev environment, both transports
have a dsn set to sync://.
I do want to mention that the queue_name option is something that's specific
to Doctrine. The sync transport doesn't use that, and so, it…
High Priority Transports
…which in our
case is using doctrine. Below, add options, then queue_name set to high.
The name high isn't important - we could use anything. The queue_name option
is specific to the Doctrine transport and ultimately controls the value of a column
in…
Problems with Entities in Messages
…it's not already in the list,
it's added. Then, when we call flush(), Doctrine loops over all of these
objects, looks for any that changed, and creates the appropriate UPDATE or INSERT
queries. It knows whether or not an object should be inserted…
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…
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…
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…
Collection Criteria for Custom Relation Queries
…
Fortunately, no! These Doctrine Collection objects have a few tricks up their sleeves,
including a special "criteria" system for just this situation. It allows us to
describe how we want to filter the answers and then it uses that when it queries!
Remove the filter…
Login with json_login
…section. This was added in the
last tutorial for us by the make:user command. It tells the security system
that our User lives in Doctrine and it should query for the user via the email
property. If you have a more complex query... or…
Setup: For Dependent Select Fields
…location will be
optional. Now run:
php bin/console make:migration
and open the Migrations/ directory to check out that new file.
No surprises here, so let's go back and run it:
php bin/console doctrine:migrations:migrate
Perfect!
Next, open the ArticleFormType so…
EntityType: Drop-downs from the Database
…Anyways,
we'll see in a minute how we can control what's displayed here.
So... great first step! It looks like the form guessing system correctly sees the
Doctrine relation to the User entity and configured the EntityType for us. Go
team!
But now…
Customizing the User Entity
…But! A word of warning. Check out
the roles field on top:
It's an array and its Doctrine type is json. This is really cool. Newer
databases - like PostgreSQL and MySQL 5.7 - have a native "JSON" column type
that allows you to store…
All about the User class
…And actually,
it's not that important. I'll tell you what it does later.
But before we get there, forget about security and remember that our User class
is a Doctrine entity. Let's add another field to it, generate a migration & add
some…
Fixture References & Relating Objects
…for each loop. For the second argument, it passes
the object itself.
This reference system is a little "extra" built into Doctrine's fixtures library.
When you add a "reference" from one fixture class, you can fetch it out in another
class. It's super…
x
1000+