The difference between the doctrine: mapping: convert and doctrine: mapping: import

I want to create entity classes from a database for my symfony application. So, I performed the following three steps (From How to create entities from an existing database )

1. php app/console doctrine:mapping:convert yml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force 2. php app/console doctrine:mapping:import AcmeBlogBundle yml 3. php app/console doctrine:generate:entities AcmeBlogBundle 

To find out about the work of these three commands, I simply deleted all the files from ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm . I added another field to one table. After that, I executed command-2 and command-3.

I checked the modified table object for the new field. A new field was present in the facility.

Then why do we use the doctrine: mapping: convert command to create entities from an existing database?

+4
source share
3 answers

After creating the entity classes, Doctrine is intelligent enough to get all the necessary information to import the mapping from Entity classes without requiring the class metadata obtained in the first step. If you deleted metadata and entity classes, you would not be able to complete step 2 without completing step 1.

+2
source

I don’t quite understand what you are saying there, because for me I need 3 teams and different teams.

If you want to inherit the database schema to generate the necessary Symfony ORF files and entities, you must use 3 commands.

Here's what they do: 1)

 php app/console doctrine:mapping:convert yml ./src/< vendor>/< bundle_name>/Resources/config/doctrine/metadata/orm --from-database --force 

This creates entity mapping files from the database by introspection. For each table in the database, this will simply generate <entity> .orm.yml in:

 < proj_folder>/src/< vendor>/< bundle_name>/Resources/config/doctrine/metadata/orm/< entity>.orm.yml 

2)

 php app/console doctrine:mapping:import < vendor>< bundle_name> annotation** 

Generate entity classes for each table introduced from the database:

OUTPUT: writing /var/www/html/< project_folder>/src/< vendor>/< bundle_name>/Entity/< entity>.php

3)

 php app/console doctrine:generate:entities < vendor>< nameBundle>** 

This only generates recipients and setters for all properties of the entity class.

+6
source

What I know, and as I explained this in this post , mapping: convert cannot resolve namespaces for relationships in your model . Therefore, you need to handle the mapping: import and get the final mapping files. After matching: the import has been processed, you can delete the directory YourBundle/Resources/config/doctrine/metadata/orm .

+3
source

All Articles