Doctrine/Symfony entity generator and generating entity from one table

纵饮孤独 提交于 2020-02-24 12:08:31

问题


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:


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.



来源:https://stackoverflow.com/questions/35225929/doctrine-symfony-entity-generator-and-generating-entity-from-one-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!