在 Symfony 2 中使用 Doctrine 2 中的视图
我有一个订单数据库(简化): 订单:{id、发货、折扣、日期} order_item: {id, order_id, name, amount, Price}
如果我想获得全价(SUM(商品价格)+发货折扣),我当然可以向我的 Order 类添加一个执行查询的方法。另一方面,查看包含全价的订单会很方便。
是否可以将其集成到 Doctrine2 实体对象中?当我使用 Symfony/Doctrine 维护数据库布局时,是否可以通过类中的注释生成这样的视图?
I have a database for orders (simplified):
order: {id, shipment, discount, date}
order_item: {id, order_id, name, amount, price}
If I want to get the full price (SUM(item prices)+shipment-discount) I could of course ad a method to my Order class that does the query. On the other hand, it would be handy to have a view on order that includes the full price.
Is it possible to integrate that into a Doctrine2 entity object? Is it even possible to generate such a view via annotations in the class, as I am maintaining my database layout with Symfony/Doctrine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有 Doctrine Entity 和 EntityRepository。
查询应该作为方法进入存储库类。 mysql-view 只是一个查询。存储库类返回一个或多个实体类。IE 数据库表中的行。
请提供一些代码和架构,以获得更好的答案。
这可以转到订单实体:
Doctrine2 不支持本机 MySQL 视图处理和生成。
You have Doctrine Entity and EntityRepository.
Queries should go to Repository Classes as a method. A mysql-view is just a query. A Repository Class returns one or more Entity classes.. I.E Row in Database Table.
Please provide some code and schema, to get better answers.
This could go to Order Entity:
Native MySQL Views handling and generating is not supported by Doctrine2.
嗯,可能吗?我不知道。我认为为这些实体创建一个自定义存储库是最好的。方法中带有查询的实体不干净。
这里有一个使用实体和自定义查询的方法示例
http://www.zalas.eu/doctrine2-and-symfony2
mmm ¿Posible? I don't know. I think doing a custom repository for these entity would be the best. Entities with queries in its methods are not clean.
Here there is an howto example working with entities and custom queries
http://www.zalas.eu/doctrine2-and-symfony2