如果使用业务逻辑扩展了 yml 创建的实体,如何更新它们?
当您使用一组包含关系映射的 yml 文件执行doctrine:generate:entities 时,将自动生成所有实体类。
当您调整 yml 文件并重新生成实体类时,它们会被覆盖(并且旧的会被备份)。
在doctrine1中,实体生成器创建了由实际实体类自动继承的基类,您可以使用自己的业务逻辑对其进行扩展。
在doctrine2中,我看不到那些基类,并且我不想调整生成的类,因为我无法更新 yml 文件中的数据模型。
Doctrine2 方法是什么? 我应该手动继承生成的实体类来添加业务逻辑吗? 学说可以调整实体类,并保留额外的更改(使用某种比较算法)吗? 实体生成是否仅使用一次来生成类,并且所有数据模型更改都应该在类本身中手动实现吗?
when you execute doctrine:generate:entities with a set of yml files containing your relation mapping, all Entity classes are automatically generated.
When you adjust your yml files and regenerate the Entity classes, they are overwritten (and the old ones are backed up).
In doctrine1, the entity-generator created Base Classes that where automatically inherited by the actual Entity Class, that you could expand with your own business logic.
In doctrine2 I don't see those base classes, and I don't want to adjust my generated classes, because i won't be able to update my datamodel in my yml files.
What is the Doctrine2 approach?
Should i manually inherit from my generated Entity Classes to add business logic?
Can doctrine adjust the Entity class, and keeping the additional changes (with some sort of diffing algorithm)?
Does the entity-generation only be used once to generate the classes, and should all the datamodel changes be implemented manually in the Class itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Doctrine2 中,您可以根据需要对实体进行编程(使用相应的字段、getter 和 setter、自定义业务逻辑等),然后创建 yaml(或 xml、注释等)映射。 Doctrine2 然后生成的是与您的映射相对应的数据库表,因此您的实体始终会被保留。
我建议您查看 Doctrine2 快速入门指南,它将很好地介绍 Doctrine2 ORM 方法。
In Doctrine2 you program your entities as you wish (with respective fields, getters and setters, custom business logic, etc.), and then create the yaml (or xml, annotations, etc.) mappings. What Doctrine2 then generates are the DB tables which correspond to your mappings, so your entities are always preserved.
I suggest you take a look at the Doctrine2 Quick Start Guide, it will give a pretty good idea of the Doctrine2 ORM approach.