Adding More Columns
…above each:
These tries to guess the right field type - but it's not always right. speciesCount
should clearly be an integer - set it to that. For a full-list of all the built-in
Doctrine types, check their docs. The most important are string…
Creating an Entity Class
…need a use statement for it. This
will look weird, but add a use for a Column class and let it auto-complete from
Doctrine\ORM\Mapping. Remove the Column part and add as ORM:
Every entity class will have that same use statement. Next…
Sharing Data between Fixture Classes
…ORM/LoadUsers.php
// ...
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
class LoadUsers implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
{
}
Head over to LoadEvents and make the same change, except returning 20
so that the class is run second:
// src/Yoda/EventBundle/DataFixtures/ORM/LoadEvents.php
// ...
use Doctrine\Common\DataFixtures\OrderedFixtureInterface…
Introduction
…the hood. We’ll learn what a service is, find out more about the core Symfony
services and create a few of our own. In Doctrine, we’ll create some ManyToOne
and ManyToMany relationships. We’ll also talk about lifecycle callbacks and
event listeners. And…
Introduction
…some of the most difficult areas of Symfony, like security, forms, and
some serious Doctrine topics. Some of this stuff will look pretty tough at
first, but that’s just because we’re taking your Symfony foo up to the next
level. When you finish…
Adding Outside Bundles with Composer
…are dummy data we put into the database.
When we started the project, we downloaded the Symfony Standard edition:
our pre-started project that came with Symfony and other tools like Doctrine.
Unfortunately, it didn't come with any tools for handling fixtures.
But we…
Code Generation FTW!
…we 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 inquisitive command first wants to know which entity we need a…
Inserting and Querying Data
…the error straight
from MySQL saying that the details column can't be null.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'details' cannot be null
So Doctrine assumes by default that all of your columns should be set to NOT NULL
when creating the table…
Translatable Mapping
…and slick approach is to use PHP
attributes.
I'm all for slick and modern, so let's go with attributes.
These will be similar to these Doctrine ORM mapping attributes. Ours will
map translatable entities and properties.
In our object-translation-bundle/src directory…
MakerBundle & Autoconfiguration
…Ooh. There's a ton of stuff here for setting up
security, generating doctrine entities for the database (which we'll do in the next
tutorial), making a CRUD, and much more.
Let's try one: how about we try to build our own new…
Extending with Events
…it says "Updated By", "Null". Our goal is to set that field automatically
when a question is updated.
A great solution for this would be to use the doctrine extensions library and
its "blameable" feature. Then, no matter where this entity is updated - inside
the…
AMQP Priority Exchange
…in different "queues". Then we can instruct our worker to first read all messages
from whatever queue async_priority_high is bound to before reading messages
from whatever queue the async transport is bound to.
This did work before with Doctrine, thanks to this queue…
Partial Handler Failures & Advanced Routing
…there's a problem removing this ImagePost from
the database, Doctrine will throw an exception right here and the file will never
be deleted. That's perfect: the row in the database and file on the filesystem
will both remain.
But if deleting the row…
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…
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…
Starting in Symfony2: Course 1 (2.4+)
…from
the ground-up, touching on and discussing the most fundamental parts
of the application. Specifically, we'll cover:
Installation, Git and Setup
Composer
Routing
Controllers
Introduction to the service container
Twig
Doctrine
Server setup
Code generation
Fixtures & external libraries
And other tips and tricks
Joining Across a ManyToMany
…Behind the scenes, to get this
data, Doctrine will need to query across the join table and the tag table.
But... we don't really care about that! We just get to say question.tags and
that returns all the Tag objects for this Question…
Joining Across a Relationship & The N + 1 Problem
…text. The moment we do
that, Doctrine makes a second query from the question table to get that answer's
question data: so in this case WHERE id = 463. Then we render the second answer...
and make another query to get its question data..…
Rendering Answer Data & Saving Votes
…templates/question/show.html.twig.
If you scroll down a bit - here it is - we loop over the answers variable. That
will still work: the Doctrine collection is something that we can loop over.
But the answer variable will now be an Answer object. So…
The ManyToOne Relation
…want to do is relate an Answer to a Question.
To do this... well... forget about Doctrine for a second. Let's just think about
how this would look in a database. So: each answer belongs to a single question.
We would normally model this…
x
1000+