Database Migrations
…To guarantee that this is unique in the database, add unique=true:
This option does only one thing: it tells Doctrine that it should create a unique
index in the database for this column.
But of course, the database didn't just magically update to have…
Mapped Superclasses
…over to the console and see what our schema update will
look like. Run:
symfony console doctrine:schema:update --dump-sql
The dump-sql flag just outputs the SQL that would be executed.
At the end here, notice that we're dropping the starship table…
Adding a Search + the Request Object
Time for a quick, but useful, detour away from Doctrine Relations. I know
Doctrine relations rock, but so will this! I want to add a search bar to our
page. Trust me on this one, it's going to be good.
Pop open the index…
The QueryBuilder
It's really powerful to understand that DQL is ultimately what's being used behind
the scenes in Doctrine. But most of the time, we're not going to build this DQL
string by hand. Nope, we're going to use something called the "QueryBuilder…
Entities in a Bundle
Our bundle needs a way to store the object translations. Since we're
translating Doctrine entities from the database, we know a database is
in use. So the best way to store these translations is also in the
database.
Here's the plan: we're…
Entity Class
…with one called title. Next it asks which type this
field is. Hit ? to see the full list.
These are Doctrine types... and each one will map to a different column type
in your database, depending on which database you're using, like MySQL or…
AMQP with RabbitMQ
…a high level... it doesn't work much differently
than our simple database table: you put messages in... then ask for them later.
So... what are the advantages of using RabbitMQ instead of Doctrine? Maybe...
nothing! What I mean is, if you just use the…
AMQP Internals: Exchanges & Queues
We've just changed our messenger configuration to send messages to a cloud-based
RabbitMQ instance instead of sending them to Doctrine to be stored in the database.
And after we made that change... everything... just kept working! We can send messages
like normal and…
The Answer Entity
…s in the migrations/ directory. And... perfect!
CREATE TABLE answer... and then it adds all of the columns.
Run the migration with:
symfony console doctrine:migrations:migrate
All good! Our database now has a question table and an answer table.
Next, let's relate them.
Owning Vs Inverse Sides of a Relation
…kind of, complex topic in Doctrine relations that we need to talk about.
It's the "owning versus inverse side" of a relationship.
We already know that any relation can be seen from two different sides: Question
is a OneToMany to Answer...
and that same…
And WHERE Or WHERE
The most common thing to do in a query is to add a WHERE clause. Unfortunately,
Doctrine doesn't support that. I'm kidding!
I have a search box - let's search for "Lucky Number". This isn't hooked
up yet, but it adds a…
The Skills List Page + A Grid of Skills
Thanks to the Contentful integration, in addition to our doctrine_recipe value
type, we now have a second value type that can load things from Contentful.
This means that we can render lists and grids of skills inside any layout,
like over here on our…
ManyToMany: The Inverse Side of the Relationship
Our goal is clear: list all of the genuses studied by this User.
Back in our Doctrine Relations tutorial, we learned that every
relationship has two different sides: a mapping, or owning side, and an inverse side.
In that course, we added a GenusNote entity…
Symfony 3: Level up with Services and the Container
Our app is coming to life! Thanks to the Doctrine Course
we have a rich data model. And after the course on Configuration,
well, using and configuring services is simple.
Now it's time to level-up with those services. These
puppies are the backbone…
Starship Entity
…Starship needs a name.
Next is class, it'll be the same as name... then captain is also a simple string.
Next: status. Doctrine defaults to a string, but...
look at our Starship model, status is an enum. How
can we map this to a…
Single Table Inheritance
Alright, so in order to be able to fetch all the starships at once, we
need to use Doctrine's second type of inheritance: Single Table Inheritance.
With this feature, all entities that are part of the hierarchy are stored in
a single table. This…
Operations / Endpoints
…Platform works by taking a class like DragonTreasure and saying that you want
to expose it as a resource in your API. We do that by adding the ApiResource
attribute:
Right now, we're putting this above a Doctrine entity, though, in a future
tutorial…
Persisting the More Complex Many-to-Many Relationship
We refactored our many-to-many relationship to include a join entity
called StarshipDroid, instead of relying on Doctrine to create
the join table for us. Reload our fixtures, but hold on to your
hats:
Error!
Undefined property: App\Entity\Starship::$droids
This error is…
Configuring our Bundle's Entity
…right now. This
command also shows mapped superclasses, so we need to do some work
to get our Translation class to show up here.
You're probably used to using mapping attributes for your Doctrine entities.
In bundles, it's a bit different. The official…
Filters: Automatically Modify Queries
…But what if we want to apply some criteria like this globally to
every query to a table? Like, telling Doctrine that whenever we query for fortune
cookies, we want to add a WHERE discontinued = false to that query.
That sounds crazy. And yet…
x
1000+