使用 symfony2 和教义从现有数据库生成单个实体

2022-01-16 00:00:00 database php symfony doctrine

是否可以使用 Symfony2 控制台工具从数据库生成单个实体?

Is it possible to generate a single entity from database using the Symfony2 console tool?

在编码过程中,我不得不添加一个表,并对现有的实体类进行了修改.所以我不希望我的所有实体都重新生成.

In the middle of coding I had to add a table and there are modifications made to the existing entity classes. So I don't want all my entities regenerated.

任何建议将不胜感激!

推荐答案

我遇到了同样的问题,你必须这样做:

I had the same problem, you've to do this way:

php app/console doctrine:mapping:convert metadata_format 
    ./src/App/MyBundle/Resources/config/doctrine 
    --from-database 
    --filter="Yourtablename"

然后

php app/console doctrine:mapping:import AppMyBundle 
    metadata_format --filter="Yourtablename"

其中 metadata_format 是您要生成的文件结尾(例如 xml、yml、注释)

Where metadata_format is the file ending you want to generate (e.g. xml, yml, annotation)

最后

php app/console doctrine:generate:entities AppMyBundle --no-backup

就像这个学说只会加载你需要的实体.请注意必须使用 CamelCase 的过滤器!

Like this doctrine will load only the entity you need. Just be carefull on the filter you must use the CamelCase !

希望对你有帮助

相关文章