Search, the Request Object & OR Query Logic
…we were already
filtering WHERE status = approved. But because we put the OR statement inside
of the andWhere(), Doctrine surrounded the entire fuzzy search part with parentheses.
If we had used orWhere(), that wouldn't have happened... and our query logic
would have been…
Custom Resource PUT Operation
…But what if the built-in filters aren't enough? What if we need to add some
custom filtering logic? Let's do that next by first creating a custom filter
for a Doctrine entity and later creating a custom filter for our DailyStats
resource.
Custom Resource GET Item
…Next, let's talk about
pagination. Because if we go back to /api/daily-stats.jsonld and refresh...
there are a lot of items here. Since we're not using Doctrine, we no longer
get pagination for free. If we need it, we have to…
Validating Who/When Can Publish
…new data has been
deserialized into it. The failure is from our first test case: we currently
allow this item to be published, even though the description is short. Next,
let's prevent this. How? It's back to our "original data" trick from Doctrine.
Building really fast applications (Tobias Nyholm)
…they're only heavy in when you actually using them. Makes sense. Lovely. So this is cool and all. Let's move on to doctrine. Look at this five lines of code. It's a form. For yourself, think about potential issues with this code…
Filtering Related Collections
…method:
public function getPublishedCheeseListings() that will also return a Collection.
Inside, return $this->cheeseListings->filter(), which is a method on Doctrine's
collection object. Pass this a callback function(){} with a single CheeseListing
argument. All that function needs is return $cheeseListing->getIsPublished().
If you're…
Logging in Inside the Test
…ids. Try this:
$em = self::$container - a parent class sets the container on this nice property -
->get() and the service id. Use doctrine then say ->getManager().
You can also use the type-hint you use for autowiring as the service id. In
other words…
Removing Items from a Collection
…the $cheeseListings
property, add orphanRemoval=true.
This means, if any of the CheeseListings in this array suddenly... are not
in this array, Doctrine will delete them. Just, realize that if you try to
reassign a CheeseListing to another User, it will still delete that
CheeseListing. So…
Creating the User Entity
…make:migration
Move over... and double-check the SQL: CREATE TABLE user - looks good!
Run it with:
php bin/console doctrine:migration:migrate
Perfect! We have a gorgeous new Doctrine entity... but as far as API Platform
is concerned, we still only have one API…
@SerializedName & Constructor Args
…Symfony 4.3, you may already see a validation error!
That's because of a new feature that can automatically convert your database
rules - the fact that we've told Doctrine that title is required in the
database - into validation rules. Fun fact, this feature…
Registration Form
…console make:migration
Let's go check out that new file. Yep! No surprises: it just makes the column not
required.
Move back over and run this with:
php bin/console doctrine:migrations:migrate
Excellent! Let's try to register! Register as geordi@theenterprise.org…
Security & the User Class
…for now. We will add a password later, but we'll keep
things extra simple to start.
And... we're done! Awesome! This created a User entity, a Doctrine UserRepository
for it, and updated the security.yaml file.
Let's check out these changes next!
The Twig Extensions Library
…actually, a better question is: should
we solve this? Here's the point: you need to be aware of the fact that Doctrine's
nice relationship lazy-loading magic makes it easy to accidentally make many queries
on a page. But, it is not something…
ManyToMany Relationship
…owning versus inverse stuff is important because, when Doctrine
saves an entity, it only looks at the owning side of the relationship to figure
out what to save to the database. So, if we add tags to an article, Doctrine will
save that correctly. But…
Query Joins & Solving the N+1 Problem
…make sense anymore? I mean, if we're already making a
JOIN to the article table, isn't this extra query unnecessary? Doesn't Doctrine
already have all the data it needs from the first query, thanks to the join?
The answer is... no, or…
Request Object & Query OR Logic
…places. One mistake could lead to an OR causing many more results
to be returned than you expect!
To best handle this in Doctrine, always use andWhere() and put all the OR logic
right inside: c.content LIKE :term OR c.authorName LIKE :term. On…
Fun with Commands
…if you needed your SlackClient service,
you would just add a __construct() method and autowire it!
With our new knowledge, let's keep going and start mastering features, like the
Doctrine ORM, form system, API stuff and a lot more.
Alright guys, seeya next time…
x
1000+