Query Logic Re-use Shortcuts
... hint - the one from Doctrine\ORM - and $qb:
Next, go up, copy that part of the query, and just return
$qb->andWhere('a.publishedAt IS NOT NULL'):
And since we're returning this - and each query builder method returns ...
Sluggable other Wonderful Behaviors
...
slug is unique. So, if a slug already exists in the database, it adds a -1
, -2, -3, etc. until it finds an open space.
Side note: this feature is built on top of Doctrine's event system. Google for
"Doctrine Event ...
Services
...
There's a lot more to say about the topic of services, and so many other parts
of Symfony: configuration, Doctrine & the database, forms, Security and APIs, to
just name a few. The Space Bar is far from being the galactic ...
Final config Migration
... also delete config_prod.yml.
Oh, by the way, if you have some doctrine caching config in config_prod.yml,
I would recommend not migrating it. The DoctrineBundle recipe gives you prod
configuration that is great for ...
Migrating framework Config
... validation line!
What's really interesting is that enable_annotations is set to true because
it detected that we have the Doctrine annotations package installed. This is the
flow with Flex: install a package and you're done.
Ok! It might not look like it, but we're almost done with the framework stuff.
Let's finish it next!
Exceptions Part 2 Adding Fence Security
... .. unless there's
some security to keep it inside.
We've reached the third step of TDD once again: refactor. Actually, I don't need
to refactor, but now is a great time to add the missing Doctrine annotations.
Above the ...
Tests Assertions Coding
... property. It does have Doctrine annotations,
but that's not important! Sure, we will eventually be able to save dinosaurs to
the database, but our test doesn't care about that: it just checks to make sure
setting and ...
Priming cache.app
... automatically makes
available. You can also use cache.adapter.filesystem - which is the default -
doctrine, apcu, memcached or create your own service. If you need to configure
Redis, use the default_redis_provider key under app ...
Safe Migrations
...
./bin/console doctrine:migrations:diff
Go check it out in app/DoctrineMigrations. Wow... it's actually perfect:
ALTER TABLE video CHANGE image (to) poster...
Doctrine is smart ...
Void Types Refactoring an Entire Class
... flexible interface. But actually, for Doctrine collections,
you must use Collection. Depending on the situation, this property might be an
ArrayCollection or a PersistentCollection... both of which implement the
Collection ...
Using a Test Database
... do that, we can setup the test environment to use a different database
name. Open config.yml and copy the doctrine configuration. Paste it
into config_test.yml to override the original. All we really want to
change is ...
Weird Endpoint The tagline as a Resource
... should be /api/programmers/{nickname}/tagline.
To be super hip, add an @Method annotation: we know this should only match PUT requests:
Like before, type-hint the Programmer argument so that Doctrine will query for
it for ...
Pagerfanta Pagination
... () - since we're using Doctrine - and pass it
the query builder. Next, create a $pagerfanta variable set to new Pagerfanta()
and pass it the adapter.
On the Pagerfanta object, call setMaxPerPage() and pass it 10. And then ...
Adding to a Collection Cascade Persist
... Genus.genusScientists that
was not configured to cascade persist operations for GenusScientist.
Umm, what? Here's what's going on: when we persist the Genus, Doctrine sees the
new GenusScientist on the genusScientists array... and ...
Tracking Cancelations in our Database
... () and then saving it to the database with
the standard persist() and flush() Doctrine code:
And that should do it! Let's give this guy a try. Go to the account page, then press
the new "Cancel Subscription" button. Ok ...
Give the User a Subscription in our Database
... $stripeSubscription->id:
Booya!
And, time to save this to the database! Since we're using Doctrine in Symfony, we
need the EntityManager object to do this. I'll use dependency injection: add an
EntityManager argument to the ...
After-dinner Mint
... it and set a nullable=true option in the Doctrine metadata. Don’t
worry about updating your schema - this change is just temporary:
// src/Yoda/UserBundle/Entity/User.php
// ...
/**
@ORM\Column(type="string", length ...
Server-Side Validation
... \Doctrine\Validator\Constraints\UniqueEntity;
/**
@ORM\Table(name="yoda_user")
@ORM\Entity(repositoryClass="Yoda\UserBundle\Entity\UserRepository")
@UniqueEntity(fields="username", message="That username is taken ...
Code Generation FTW
... need a CRUD for the Event entity.
Want to use Doctrine to generate a CRUD? Yea, there's a console command for
that doctrine:generate:crud:
php app/console doctrine:generate:crud
This ...
Making an Argument Available to All Controllers
... object
via Doctrine with that id, and then adds a new request attribute called post
that’s set to that object:
// Summarized version of ParamConverterListener
public function onKernelController(FilterControllerEvent $event ...
2710
Doctrine
Filter Results