1000 search results

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…

3:24
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…

4:53
Passing Entity Ids inside of Messages

…Enter -> Initialize Fields to create that property and set it. Back in the method, we can say $imagePost = $this->imagePostRepository->find($imagePostId). That's it! And this fixes our Doctrine problem! Now that we're querying for the entity, when we call flush()…

8:00
Transport: Do Work Later (Async)

…supermarket. Out-of-the box, Messenger supports three: amqp - which basically means RabbitMQ, but technically means any system that implements the "AMQP" spec - doctrine and redis. AMQP is the most powerful... but unless you're already a queueing pro and want to do something crazy…

7:33
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: …

5:26
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…

5:54
Simpler State Processor

…to it. The other way - which we did in the last tutorial for this class - is to decorate the core processor. Here, we decorated the PersistProcessor from Doctrine... which means that whenever any API resource is saved, when it tries to use the core PersistProcessor…

5:47
Running Code "On Publish"

…DragonTreasure objects, loop over them, then use Doctrine's UnitOfWork to see what each DragonTreasure looked like when it was originally loaded from the database. Should we use that same trick here to see what the isPublished property originally looked like? We could... but there…

6:05
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/…

8:30
Resetting the Database

…method and run code here that does that. Fortunately, we don't need to because there are multiple libraries that already solve this problem. My favorite is Foundry. Run: If you watched our Doctrine tutorial, you'll remember Foundry! But you may not know about…

4:47
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…

5:19
How does the Controller Access the Container?

…And AbstractController implements a special interface called ServiceSubscriberInterface. This is actually something we talk about in one of our Doctrine tutorials. When you implement ServiceSubscriberInterface, it forces you to have a method called getSubscribedServices() where you return an array that says which services you need…

4:14
How to handle dynamic Subdomains in Symfony

…differences here are a bit subtle. For example, the baseHost is now stored in a property and we can get Doctrine’s repository through the $em property. We’ve also replaced the createNotFoundException call by instantiating a new NotFoundHttpException instance. The createNotFoundException method lives in…

11:43
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…

7:16
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…

6:29
Entity -> DTO Item State Provider

…the querying work manually. Instead, we'll... "delegate" it the core Doctrine item provider. Add a second argument... we can just copy the first... type-hinted with ItemProvider (the one from Doctrine ORM), and called $itemProvider. I like it! Back below, let it do the…

4:11
A World without Build Systems?

…and... hello Mixed Vinyl! But wow is this thing weird and ugly-looking. This is a Symfony 6.3 project - the same project we've built in the Symfony series. It has Doctrine installed... but there's nothing particularly special about it, and right now…

4:04
Updating an Entity

…When you call flush(), Doctrine loops over all of the entity objects that it "knows about" and "saves" them. And that "save" is smart. If Doctrine determines that an entity has not been saved yet, it will execute an INSERT query. But if it's…

5:24
Querying for a Single Entity for a "Show" Page

…is that this returns a VinylMix object. Unless you do something custom, Doctrine always gives us back either a single object or an array of objects, depending on which method you call. Now that we have the VinylMix object, let's render a template and…

8:55
The Query Builder

…have... so you might accidentally remove something you added earlier. So, always use andWhere(). Doctrine is smart enough to figure out that, because this is the first WHERE, it doesn't actually need to add the AND. Inside of andWhere(), pass mix.genre =... but…

10:04