1000 search results

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
Initialize the Bundle

…bundles already exist out there that are capable of this, but I wanted to approach it fresh, with a slightly different perspective. So that's what our bundle will do: translate Doctrine entities! Let's get started! Jump over to the code for this project…

5:03
Cascade Persist

…and... we can now see when each droid was assigned. That's it, friends! We've explored the deepest corners of Doctrine relationships, even the elusive many-to-many with extra fields. As always, if you have questions, drop them in the comments below. We…

2:51
Re-adding addDroid(): Hide that Join Entity!

…This one is pretty common in Doctrine, though not always easy to understand: A new entity was found through the relationship Starship#starshipDroids that was not configured to cascade persist for the entity StarshipDroid. This is a very fancy way of saying we've created…

1:46
Joining Across a Many-to-Many Relationship

…add a leftJoin(). But we're not going to think about the join table or the database. Nope, focus only on the relationships in Doctrine. So we're joining across s, which is our starship, and droids, the property that has the ManyToMany relationship to…

2:17
andWhere() and orWhere()

…andWhere() is always ok - even if this is the first WHERE clause... and we don't really need the "and" part. Doctrine is smart enough to figure that out. What's wrong with ->where()? Well, if you added a WHERE clause to your QueryBuilder earlier…

7: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
Bonus: Custom DQL Function

…on. It's subtle, but look at the WHERE clause: s0_.id = ?. This s0_ is an internal SQL table alias Doctrine uses - it's our starship table. I expected this to use our discriminator column, but it's using the id. I guess when…

9:01
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
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
Flex Recipe Updates

…you know, doing our real job. I'll hit enter to go down the list one-by-one. First up is Doctrine Bundle: and it's a complex update. It even caused a conflict! Sometimes we might see that a recipe update changes something - like…

6:04
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
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
Pagination & Foundry Fixtures

…method. All we need is: DragonTreasureFactory::createMany(40) to create a healthy trove of 40 treasures: Let's try this thing! Back at your terminal, run: symfony console doctrine:fixtures:load Say "yes" and... it looks like it worked! Back on our API docs, refresh…

5:44
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
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
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
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
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