The Serializer
…methods.
Cool! This will also cause the column in my database to change... so spin
over to your console and run:
symfony console make:migration
I'll live dangerously and run that immediately:
symfony console doctrine:migrations:migrate
Done! Thanks to that rename... over in…
Querying Classes
…setParameter(), for the second argument, use
$this->getEntityManager()->getClassMetadata(Scout::class).
This returns a special
metadata object for the Scout class and is what Doctrine needs to properly handle the INSTANCE OF
operator with parameters.
Refresh the browser... and nice, just the scouts again!
Try…
Multiple Submit Buttons
…it also guesses
field type options. For example, if a Doctrine entity property is nullable: true like
for this notes field:
Then Symfony will automatically make it optional. And the reverse for
the other fields, the required HTML attribute will be added if the field…
Autoconfiguration
…configuration, and environments. We are powerful! No, unstoppable.
In the next tutorial, we'll introduce Doctrine - the industry standard way to
work with databases in PHP. Until then practice. Go build something -
anything - and tell us about it. And if you have any questions, thoughts…
Submitting a Form via GET
…install and configure it, build form types,
render them with Twig helper functions, and handle submissions the right way
with Form::handleRequest(). We've looked at how forms link up with Doctrine
entities, how validation works, how to customize fields and attributes, and
how to…
Generating the API Token & Fixtures
…Instead, since
every user will already have some API tokens in the database, we can jump straight
to learning how to read and validate those tokens.
Reload the fixtures with:
symfony console doctrine:fixtures:load
And... beautiful! But since we're not going to build…
Token Types & The ApiToken Entity
…console make:migration
Spin over and peek at that file to make sure it looks good. Yup! It creates
the api_token table:
Run that with:
symfony console doctrine:migrations:migrate
And... awesome! Next: let's add a way to generate the random token string…
Subresources
…FROM dragon_treasure WHERE owner_id =
whatever we pass for {user_id}. It knows how to make that query by looking
at the Doctrine relationship and figuring out which column to use. It's super
smart.
We can actually see this in the profiler…
Bootstrapping a Killer Test System
…in the test environment, we're missing the database. We could easily fix this
by running:
symfony console doctrine:database:create --env=test
But that's way too much work. Instead, add one more trait to our test class:
use ResetDatabase:
This comes from Foundry: the…
Finding & Eliminating Deprecations
…at the end, it references
an issue from the doctrine/orm repository.
Ah! This deprecation isn't coming from Symfony: it's coming from
doctrine/orm! This tells us that we're going to need to make a change to our
code - at some point…
Hello Integration Tests!
…LockDownRepository().
But, hmm. LockDownRepository extends ServiceEntityRepository, which extends
another class from Doctrine. If you look, to instantiate it, we need to pass
a ManagerRegistry from Doctrine. And if you hold "command" or "control" and click
into this... and go to the base class, it gets…
Test Environment Database Setup
…page... it's not using the DATABASE_URL from my .env:
it's using the dynamic value that's set by the symfony binary. This is something
that we talked about in our Doctrine tutorial.
However, that magic is clearly not happening in our test…
Investigating & Retrying Failed Messages
…AMQP or Redis -
support all of the features we just saw if you use it as your failure transport.
That may change in the future, but at this moment - Doctrine is the most robust
transport to use for failures.
Anyways, as cool as failing is…
Relating Custom ApiResources
…objects... which results in it just
serializing all the properties.
This isn't a problem with entities because the serializer is smart: it reads
the Doctrine relationship metadata to figure out that a property is a collection
of some other #[ApiResource] object. Long story short…
Auto-complete Association Field & Controlling the Query
…debug toolbar... hover over the AJAX section and click to open
the profiler.
You're now looking at the profiler for the autocomplete AJAX call. Head over to
Doctrine section so we can see what that query looks like. Here it is. Click "View
formatted…
Selecting Specific Fields
…back from Doctrine is the ideal situation because...
objects are just really nice to work with. But at the end of the day, if you need
to query for specific data or columns, you can totally do that. And as we just
saw, Doctrine will…
Always Remember Me & "signature_properties"
…s password in the database. We can cheat and do
this on the command line:
symfony console doctrine:query:sql 'UPDATE user SET password="foo" WHERE email = "abraca_admin@example.com"'
Setting the password to foo is utter nonsense... since this column needs to…
Pushing & Pulling Translations
…We'll need to rely on a third-party
solution for that. A popular one is this
Doctrine Extensions package.
It has a "Translatable" behavior
that allows you to translate your entities. There's also a
Symfony Bundle
to wire it all up.
It works…
Composer
…doctrine/dbal package and added it.
With the require command, you can search for the package you need and Composer
will automatically update your composer.json for you and run the update
command to download the library. In this case, when I included the doctrine…
Using GROUP BY to Fetch & Count in 1 Query
… Only 1 query!
Yo friends, we did it! Woo! Thanks for joining me on this magical ride through
all things Doctrine Query. This stuff is just weird, cool and fun. I hope you enjoyed
it as much as I did. If you encounter any crazy…
x
1000+