在 Zend Framework 2 中处理 M-N 关系 [英] Handeling M-N Relationship in Zend Framework 2

查看:23
本文介绍了在 Zend Framework 2 中处理 M-N 关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有了 beta4 和最新的 beta5,DB-Feature-Implementation 似乎已经完成了.有几个教程如何使用 TableGateway 模式处理单个数据库,但似乎没有用于处理 M-N-关系.

With beta4 and latest beta5 the DB-Feature-Implementation appears to have pretty much finished. There's a couple of tutorials out there how to handle a single Database using the TableGateway Pattern, but it appears there is none for handling M-N-Relationships.

在 ZF1 中,我们在 TableGateway 上有 findDependantRowset(),这有点脏,因为这只是对数据库的第二个查询,这几乎并不总是必要的.

In ZF1 we had findDependantRowset() on the TableGateway which was kind of dirty, as this simply was a second Query to the databse which pretty much isn't always neccessary.

在 ZF2 中,我希望有一种方法可以将良好的连接映射到指定模型,但我在代码中找不到任何内容.也许我瞎了,也许真的没有这样的东西.

In ZF2 i expected there to be a way to have good Joins mapping to specified models, but i can't find anything within the code. Maybe i'm blind, maybe there really isn't anything like this.

你们中有人设法在 ZF2 中同时处理连接和模型吗?如果是这样,请指导我如何做,向我提示文档的具体要点或将我的一些博客文章链接到已经完成此操作的人.

Has anyone of you managed to handle joins and models all together in ZF2? If so, please be so kind to instruct me how to do it, hint me to specific points of the documentation or link me some blogpost to one who has done it.

提前谢谢各位!

推荐答案

如果您需要通用解决方案,显而易见的解决方案是使用 Doctrine ORM 或 Propel.

The obvious solution if you need a generic solution is to use Doctrine ORM or Propel.

如果您想使用 Zend\Db,那么在您的具体表网关类中,您应该编写一个从链接表中检索正确行的特定方法.这样您就可以确保 SQL 针对您需要的查询进行了优化.

If you want to use Zend\Db, then within your concrete table gateway classes, you should write a specific method that retrieves the correct rows from the linked table. This way you can ensure that the SQL is optimised for the query that you need.

这篇关于在 Zend Framework 2 中处理 M-N 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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