Keep Going!
…was probably the most important episode yet,
and you made it. Congrats!
The first big piece included the two main Doctrine associations: ManyToOne
and ManyToMany. We saw how each can have an optional inverse side, like
the OneToMany side of ManyToOne.
The second huge piece…
OneToMany: The Inverse Side of a Relationship
…we gave every Event an owner. This was our first Doctrine relationship:
a ManyToOne from Event to User.
This lets us do things like call $event->getOwner(). Let’s use this to
print the owner of an Event:
{# src/Yoda/EventBundle/Resources/views/Event/show…
Value Loader + Preview Template
…it chose to do an odd thing: explode! The Ajax call that failed says:
Value loader for doctrine_recipe value type does not exist.
To review: we have a custom value type called doctrine_recipe, which we created
so that we could add grids and…
Timestampable & Failed Migrations
…Yup! It looks
good: it adds the two columns.
Back at the terminal, run it with:
symfony console doctrine:migrations:migrate
And... yikes!
Invalid datetime format 0000 for column created_at at row one.
The problem is that our database already has rows in the…
DQL & The Query Builder
…back is a custom class. Well, technically you don't have to have a custom
repository class - and if you don't, Doctrine will just give you an instance of
EntityRepository. But in practice, I always have custom repository classes.
Anyways, when we ask for…
Persisting to the Database
…How can I insert a new row in the question table?
We need to think:
Let's create a Question object, populate it with data and then ask Doctrine
to save it.
To play with all of this, let's add a new, sort of…
Migrations
…the database. But... that table does not exist yet.
How can we create it?
Well, because Doctrine has all of this configuration about the entity, like
the fields and field types, it should - in theory - be able to create the table
for us. And... it…
Fixing our Deprecations: Form, Controller & Mailer
…the current list for the homepage.
There are technically 12 deprecations. But remember, we can ignore all the
ones from doctrine/persistence because they're not related to Symfony.
With that in mind... if you look closely, there are really only two real
deprecations left..…
Upgrading to Symfony 5.0
We've done it! We fixed all the deprecations in our app... except for the
doctrine/persistence stuff, which we don't need to worry about because we're
not upgrading that library. That means... we are ready for Symfony5!
How... do we actually upgrade…
The Server & New IsGranted
… First, in .env, change the database name to symfony3_tutorial,
or whatever the database name was called when you first setup the project. Now
when we run doctrine:migrations:status... yes! We have a full database!
Let's start the built-in web server:
./bin…
Migrating Services & Security
…goal: to move our code - which mostly lives in config/ - into
the new directory structure.
The next section is doctrine... and there's nothing special here: this is the
default config from Symfony 3. Compare this with config/packages/doctrine.yaml.
If you look closely…
Aliases & When Autowiring Fails
…wrong. Right now, the
MarkdownTransformer class has two arguments, type-hinted with MarkdownParserInterface
and Cache from Doctrine:
But, these are not being autowired: we're explicitly specifying each argument:
If I were creating this service today, I actually wouldn't specify any configuration
at first…
Criteria System: Champion Collection Filtering
…But if - in our template, for example - we wanted to loop over the experts,
maybe to print their names, Doctrine would be smart enough to make a SELECT statement
for that data, instead of a COUNT. But that SELECT would still have the WHERE clause…
Create Genus Note
…again! Welcome back friend! In this tutorial, we're diving back into
Doctrine: this time to master database relations. And to have fun of course - databases
are super fun.
Like usual, you should code along with me or risk 7 years of bad luck. Sorry…
Starting in Symfony2: Course 2 (2.4+)
…we're going to take you through some of the most difficult areas of Symfony learning all about security, forms, and parts of Doctrine. We'll also see testing and learn more about how Symfony's service container works. When you get to the end…
Creating the User Class
…If we had said no to the password question earlier, this interface wouldn't be implemented.
Back in User, we see the standard Doctrine entity class attribute: ORM\Entity. We also have this
ORM\UniqueConstraint attribute. This creates a unique index on the email column…
Ship Upgrades: Updating an Entity
…on our homepage only lists incomplete starships, so we need to find a
completed one. In your terminal, run:
symfony console doctrine:query:sql 'SELECT slug, status FROM starship'
lunar-marauder-1 is a completed ship. Copy the slug, and back in the app,
visit…
Inserting Data via Fixtures
…paste some code from the tutorial/ directory.
We now have three ship objects, but nothing has been saved - or persisted to the
database yet. But interesting, Doctrine passes us an ObjectManager.
This is the heart of Doctrine. We'll use it to save, fetch, update…
Pagination
…s a generic pagination library
but has great Doctrine integration! Add the two required packages:
composer require babdev/pagerfanta-bundle pagerfanta/doctrine-orm-adapter
Scroll up to see what this installed. pagerfanta/doctrine-orm-adapter is the glue between
Pagerfanta and Doctrine.
On our homepage…
x
1000+