1000 search results

Embedded Write

…our data, created a new User object and then set the username onto it. Doctrine failed because we never told it to persist the new User object. Though... that's not the point: the point is that we don't want a new User! We…

7:29
Relating Resources

…ll do our standard double-check to make sure the migration isn't trying to mine bitcoin. Yep, all boring SQL queries here. Run it with: symfony console doctrine:migrations:migrate And it explodes in our face. Rude! But... it shouldn't be too surprising…

7:08
Creating a User Entity

…run: symfony console make:migration Then... spin over and open that new migration file. No surprises: it creates the user table: Close that up and run it with: symfony console doctrine:migrations:migrate Sweet! Though, I think our new entity deserves some juicy data fixtures…

4:06
Inheritance with Twig

…if statement... like if ship.type == 'freighter', but that would get messy really fast. Instead, let's use Twig template inheritance. Twig Template Inheritance with Doctrine Inheritance, I love it! First, in the templates/starship directory, create a new teaser directory. This will be…

4:42
Bonus: Messenger Monitor Bundle

…but I don't have migrations configured for this project. So in your terminal, run: symfony console doctrine:schema:update --force Before we check out the UI, the bundle has two optional dependencies that I want to install. First: composer require knplabs/knp-time-bundle…

7:56
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
Query Extension: Auto-Filter a Collection

…we did with the PersistProcessor. Except... that won't quite work. Why? The CollectionProvider from Doctrine executes the query and returns the results. So all we would be able to do is take those results... then hide the ones we don't want. That's..…

6:15
Foundry: Fixtures You'll Love

…But first... let's run blindly forward and use this class! In AppFixtures, delete everything and replace it with VinylMixFactory::createOne(). That's it! Spin over and reload the fixtures with: symfony console doctrine:fixtures:load And... it fails! Boo Expected argument type "DateTime", "null"…

7:20
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
Docker & Environment Variables

…cool. By the way, if you want to see all the environment variables the Symfony binary is setting, you can run: symfony var:export --multiline But the most important one by far is DATABASE_URL. Ok: Doctrine is configured! Next, let's create the database…

3:43
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
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
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
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
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
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
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
docker-compose & Exposed Ports

…Thanks to some magic between Docker and the Symfony binary, this is going to be super easy. To start, remember when the Doctrine recipe asked us if we wanted Docker configuration? Because we said yes, the recipe gave us docker-compose.yml and docker-compose…

6:53