1000 search results

Database Migrations

…But this bundle primarily gives us something different: a new set of console commands. Run bin/console with no arguments: Hiding in the middle is a whole group starting with doctrine:migrations. These are our new best friend. Our goal is to find a way…

4:12
Query for a List of Genuses

…create a new page that will show off all the genuses. Create public function listAction() and give it a route path of /genus: Remember, everything in Doctrine starts with the all-powerful entity manager. Just like before, get it with $em = $this->getDoctrine()->getManager…

2:14
Custom Queries

…and-seek down in the web debug toolbar. Ah, it turns out this is an EntityRepository object - something from the core of Doctrine. And this class has the helpful methods on it - like findAll() and findOneBy(). Ok, wouldn't it be sweet if we could…

6:16
Injecting the Cache Service

…Perfect! We know this won't work: there is no get() function in this class. And more importantly, we don't have access to the doctrine_cache.provider.my_markdown_cache service. How can we get access? Dependency injection. This time, add a second argument…

4:23
The Mysterious "User Provider"

…the user provider is responsible for loading the User from the session and making sure that it's up to date. In Doctrine, we'll want our's to re-query for a fresh User object to make sure all the data is still up…

2:18
Filters

…put anything in DiscontinuedFilter yet, but most of the work is done. That ClassMetadata argument is your best friend: this is the Doctrine object that knows everything about the entity we're querying for. You can read your annotation mapping config, get details on associations…

10:29
Contentful: Loading Data from an External CMS

…what we're doing, it's a pretty quick process and would give us a lot of power on our site. But one of the beautiful things about Layouts is that our value types can come from anywhere: a Doctrine Entity, data on an external…

8:02
Hello Flex: Moving Final Files

…console doctrine:migrations:status Ah! I guess not! It says that my migration class wasn't found: Is it placed in a DoctrineMigrations namespace? Bah! I don't know! Our files have an Application\Migrations namespace. What's going on? Open the config/packages/doctrine

4:00
Configuring Specific (Named) Arguments

…clear out the arguments, and add $cache: '@doctrine_cache.providers.my_markdown_cache': The dollar sign is the important part: it tells Symfony that we're actually configuring an argument by its name. $cache here must match $cache here. And it works beautifully - refresh now…

3:10
Collection Filtering: The Easy Way

…that my User correctly has a studiedGenuses property with a mappedBy option... But on GenusScientist, I forgot to add the inversedBy() that points back to this: I don't really know why Doctrine requires this... since it didn't seem to break anything, but hey…

6:05
Deleting an Item from a Collection: orphanRemoval

…relationship: In other words, if we remove or add a GenusScientist from this array, it doesn't make any difference! Doctrine ignores changes to the inverse side. How to fix it? We already know how! We did it back with our ManyToMany relationship! It's…

5:14
Joining Across a ManyToMany + EXTRA_LAZY Fetch

… Yes! But now click the Doctrine icon down in the web debug toolbar to see how the queries look on this page. This is really interesting: we have one query that's repeated many times: it selects all of the fields from user and then…

5:34
Removing a ManyToMany Item

…remove the User from the genusScientists property and save. Doctrine will notice that the User is missing from that collection and take care of the rest. Let's start inside the the genus/show.html.twig template. Add a new link for each user: give…

5:16
Fetching Items from a ManyToMany Collection

…out this query happens automagically, and the matching users are set into the $genusScientists property. Yea, Doctrine just does it! All we need to do is expose this private property with a getter: public function, getGenusScientists(), then return $this->genusScientists: Now, open up the show…

3:45
Inserting into a ManyToMany

…best superhero of all time? Um, I mean, how can we insert things into this join table? How can we join a Genus and a User together? Doctrine makes this easy... and yet... at the same time... kind of confusing! First, you need to completely…

5:27
Give me Clean URL Strings (slugs!)

…But! But, but but! I have good news: if we can understand just a few important concepts, Doctrine collections are going to fall into place beautifully. So let's take this collection of chaos and turn it into a collection of.. um... something awesome... like…

5:39
Querying on a Relationship

…just like before - start with return $this->createQueryBuilder() with genus_note as a query alias. For now, don't add anything else: finish with the standard ->getQuery() and ->execute(): Doctrine doesn't know about this new repository class yet, so go tell it! In GenusNote…

3:24
OneToMany: Inverse Side of the Relation

…can think about any relationship in two directions: each GenusNote has one Genus. Or, each Genus has many GenusNote. And in Doctrine, you can map just one side of a relationship, or both. Let me show you. Open Genus and add a new $notes property…

5:08
The King of Relations: ManyToOne

…use a different example, this would be if each product had many tags, but also each tag related to many products. And when it comes to Doctrine relations - don't trust the Internet! Some people will try to confuse you with other relationships like OneToMany…

2:27
Data Persister Decoration

…object and validates it, it tries to save or persist that object. Usually, this means that we're saving an entity object to the database via Doctrine. But we could "save" an object anywhere, like by sending the data to another API, or putting it…

6:48