1000 search results

Removing Items from a Collection

…the dragonTreasures property. After cascade, add one more option here: orphanRemoval: true. This tells Doctrine that if any of these dragonTreasures become "orphaned" - meaning they no longer have any owner - they should be deleted. Let's try it. When we hit "Execute" again... got it…

3:49
Async & Retryable Sending with Messenger

…sent to be queued. We'll use the Doctrine transport as it's easiest to set up. composer require symfony/doctrine-messenger Back in our IDE, the recipe added this MESSENGER_TRANSPORT_DSN to our .env and it defaulted to Doctrine - perfect! This transport adds…

3:39
Goodbye SensioFrameworkExtraBundle

…the route does have a {slug} wildcard... but then a $mix argument, which is a Doctrine entity. Behind the scenes, the param converter would automatically query for a VinylMix where slug equals the {slug} in the URL. No annotation needed: it just worked. The good…

2:50
Adding Items to a Collection Property

…to be this object. That's important because of how Doctrine handles relationships: setting the owner sets what's called the "owning" side of the relationship. Basically, without this, Doctrine wouldn't save this change to the database. The takeaway is that, thanks to addDragonTreasure…

4:04
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
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
Email from CLI Command

…count($bookings))). Testing time! Pop over to your terminal. To be sure we have a booking that needs a reminder sent, reload the fixtures with: symfony console doctrine:fixture:load Now, run our new command! symfony console app:send-booking-reminders Nice, 1 reminder sent…

4:32
Email Twig Layout

…we aren't using migrations. So, we'll just force update the schema. In your terminal, run: symfony console doctrine:schema:update --force Then, reload the fixtures: symfony console doctrine:fixture:load That all worked, great! Next, we'll create a new reminder email and…

4:32
Upgrading to Symfony 7

Doctrine uses behind the scenes to load lazy relationships. Recently, Symfony added its own version of proxies called "ghost objects". They're spooky cool. Anyway, this proxy package isn't needed anymore. It was originally added to our app way back when we installed Doctrine

5:05
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
Leveraging the Core Processor

…on? We map the UserApi to a new User object and save the new User... which causes Doctrine to assign the new id to that entity object. But we never take that new id and put it back onto our UserApi. To fix this, after…

7:11
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
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
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
Builder in Symfony & with a Factory

…character builder needed a service like the EntityManager? With our new setup, we can make that happen. I don't actually have Doctrine installed in this project, so instead of the EntityManager, let's require LoggerInterface $logger... and I'll again add private in front…

8:18
Testing with the "in-memory" Transport

…we could query the messenger_messages table, but that's a bit hacky - and only works if you're using the Doctrine transport. Fortunately, there's a more interesting option. Start by copying config/packages/dev/messenger.yaml and pasting that into config/packages/test…

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

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

9:51