Doctrine/Symfony entity generator and generating e

2019-07-10 13:43发布

I have already a few entities, but now a new table appeared in a database, and I'd like to generate an entity on only this one table.

I already saw this, but I have further questions.

I already have a User entity (and a db table). Now, the new table is called "Report" (no entity for it right now, I want to create it) and it has a foreign key to User. There are also a few more foreign keys.

If I do what is suggested in the above answer, that is:

$ php app/console doctrine:mapping:import --force AppBundle xml --filter="Report"

$ php app/console doctrine:mapping:convert annotation ./src/AppBundle/Entity --from-database --filter="Report"

$ php app/console doctrine:generate:entities AppBundle:Report --no-backup

Will Doctrine generator try to modify my User entity? Or will just create a Report entity?

Btw. I understand(?), this it will not, because this is ManyToOne relation, but let's assume for a moment that this is ManyToMany for a moment.

I know I could simply try it, but the last time I executed the doctrine:mapping:import --force command I ended up with a crashing app and I spent many hours to solve this problem, until someone on Stackoverflow told me to remove the src\AppBundle/Resources/config/doctrine/ directory, which helped.

I didn't think about making a backup before running this command.

So, I'm a bit afraid of it... Now I created a backup, but I'm not sure if this will help in case of troubles.

1条回答
看我几分像从前
2楼-- · 2019-07-10 14:32

It depends on the /Resources/config/doctrine directory. If you empty it out and do the commands you described, then only the Report entity will be modified. If you have all of the previous mappings in that directory it should modify the User entity as well.

The commands will automatically create backups of your entities for you, so you will have a new User.php and a backup in User.php~, which you should be careful of if you are using version control and like to git add src/ without thinking too hard about it. You don't want to add those files to source control.

Either way, backups are created, and you should be using version control on top of that, so you should be fine.

查看更多
登录 后发表回答