教义/ Symfony实体生成器和从一个表生成实体 [英] Doctrine/Symfony entity generator and generating entity from one table

查看:183
本文介绍了教义/ Symfony实体生成器和从一个表生成实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有几个实体,但是现在数据库中出现了一个新表,我只想在这个表上生成一个实体。

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.

我已经有一个User实体(和db表)。现在,新表称为报告(现在没有实体,我想创建它),并且它具有User的外键。还有更多的外键。

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

Doctrine生成器会尝试修改我的User实体吗?还是只创建一个Report实体?

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

Btw。我理解(?),但不会,因为这是ManyToOne关系,但让我们暂时假设这是ManyToMany。

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.

我知道我可以只需尝试一下,但是最后一次执行 doctrine:mapping:import --force 命令时,我遇到了崩溃的应用程序,并且花了很多时间来解决这个问题,直到Stackoverflow上的某人告诉我删除 src\AppBundle / Resources / config / doctrine / 目录,这才有所帮助。

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.

推荐答案

这取决于 / Resources / config / doctrine 目录。如果将其清空并执行您描述的命令,则只会修改 Report 实体。如果您在该目录中拥有所有以前的映射,则还应该修改 User 实体。

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.

命令会自动为您创建实体的备份,因此您将拥有一个新的 User.php 和一个 User.php〜,如果您使用的是版本控制,并且喜欢 git add src / 而不用太费力地考虑,则应该小心。您不想将这些文件添加到源代码管理中。

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.

这篇关于教义/ Symfony实体生成器和从一个表生成实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆