Login to bookmark this video
Buy Access to Course
08.

Extending our Bundle's Entity

|

Share this awesome video!

|

Lucky you! You found an early release chapter - it will be fully polished and published shortly!

This Chapter isn't quite ready...

Get Notified About this Course!

We will send you messages regarding this course only
and nothing else, we promise.
You can unsubscribe anytime by emailing us at:
privacy@symfonycasts.com

Our bundle has an abstract Translation mapped superclass and is registered with Doctrine. Time to create the real Translation entity in our app.

At your terminal, run:

symfony console make:entity

For the class name, use Translation. All properties are defined in the abstract Translation class in the bundle, so just hit enter to finish.

The Real Translation Entity

In your editor, open our new entity in src/Entity/Translation.php.

Alright, here we go! The ID was added for us, which is all we need. Now to extend the abstract Translation class from the bundle. Since it has the same name, we need to import it with an alias.

At the top, write use Translation and choose the one from our bundle. Then, as BaseTranslation. Extend it with extends BaseTranslation.

Sweet, we're done with this!

Eventually, we'll provide a recipe so end users won't have to do this step.

Making a Migration

New entity? New migration!

Jump back to the terminal and run:

symfony console make:migration

Take a look at it. Open the new migration file in the migrations/ directory.

Check out the up() method. It's creating the translation table with the id, but also all the columns from our bundle's mapped superclass. Perfect!

Add a description: Add Translation entity.

Time to run it. At your terminal, run:

symfony console doctrine:migrations:migrate

Choose yes, and... boom! Database migrated!

Ok, we have the entity in our app, but in order for our bundle to perform queries on its behalf, the bundle needs to know about it. Perfect job for bundle configuration - that's next!