1000 search results

Using RAND() or Other Non-Supported Functions

…t change anything in our app... it just adds a bunch of code that we can activate for any functions that we want. To do that, back over in config/packages/doctrine.yaml, somewhere under orm, say dql. There are a bunch of different categories…

3:11
WHERE IN()

…but inside of that, instead of a comma-separated list, you'll set an array. Doctrine will transform that for us. And now... nice! Once you know how it works, it's just that easy. Next: You're probably familiar with the RAND() function for…

2:07
Criteria: Filter Relation Collections

…There it is. Below, add a new method called getFortuneCookiesStillInProduction(). This, like the normal method, will return a Doctrine Collection. And... just to help my editor, copy the @return doc above to say that this is a Collection of FortuneCookie objects. So... what do we…

9:09
SELECT the SUM (or COUNT)

…object. This is interesting too! In SQL, we would normally say something like WHERE fortuneCookie.categoryId = and then the integer ID. But in Doctrine, we don't think about the tables or columns: we focus on the entities. And, there is no categoryId property…

6:15
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
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
Filters: Searching Results

…since we're using the Doctrine ORM - because we want to allow the user to filter on a boolean field. The second thing you need top pass is properties set to an array of which fields or properties you want to use this filter on…

5:14
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
Filtering Relation Collection

…internally, Doctrine will first query for all 100... even though we'll only return 10. If you have large collections, this can be a performance problem. In our Doctrine tutorial, we talk about fixing this with something called the Criteria system. But with both approaches…

5:39
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
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
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
Events, Events & Events!

…see the Twig templates being executed below it, and even little Doctrine queries happening along the way. The biggest thing I want you to notice is that most of the other lines - both before and after the controller - contain the word Listener, or sometimes Subscriber…

5:10
Installing Messenger

…validates it, uses another service to store that file - that's the uploadImage() method, creates a new ImagePost entity, saves it to the database with Doctrine and then, down here, we have some code to add Ponka to our photo. That ponkafy() method does the…

6:15
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…

7:01
Implementing the Webhook Consumer

…method, fetch the user with $user = $this->entityManager->getRepository(User::class)->find($userId). Next, if $user doesn't exist, we'll throw new EntityNotFoundException() (choose the one from Doctrine\ORM). For the message write sprintf('User "%s" not found for LemonSqueezy webhook "%s"!', $userId…

8:10
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
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
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
Auto Setting the "owner"

…for this: the state processor system. As a reminder, our POST and PATCH endpoints for DragonTreasure already have a state processor that comes from Doctrine: it's responsible for saving the object to the database. Our goal will feel familiar at this point: to decorate…

4:19