将 Zend_Db 与 ORM 类混合
Zend 有 Zend_Db 但它不是完整的 ORM。我已经有了使用 Zend_Db 编写的应用程序的各个部分。然而,我确实希望将完整的 ORM 集成到应用程序中,以将其用于更复杂的数据库操作,但我不想重新编写已完成的现有操作。
那些对 Zend Framework 有更多经验的人,您是否发现在某些操作中使用 Zend_Db 而在其他操作中使用 ORM 存在问题? Zend_Db 生成的类是否可以与 ORM 生成的数据库类共存?如果我在一次操作中使用这两个类会怎样?我没有看到那里有冲突,但我不太擅长 MVC 或 ORM,所以我可能会错过一个大冲突。
Zend has Zend_Db but it's not a full ORM. I already have sections of an app written in a way that uses Zend_Db. I do however want to integrate a full ORM into the application to use it for more complex database operations, but I don't want to have to re-write existing actions that are complete.
Those more experienced with Zend Framework, do you see a problem with using Zend_Db in some actions and an ORM in other actions? Is it possible for Zend_Db generated classes to co-exist with database classes generated by the ORM? What if I were to use both classes even in a single action? I don't see a conflict there but I'm not that great with MVC or ORM so I may be missing a big conflict.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ZF 1.0 版本中,我在 Zend_Db 上做了很多工作,而且我也使用过一点 Doctrine。
Zend_Db 和另一个 ORM 之间不应该有任何冲突。然而,通过 Zend_Db 接口获取的对象将不知道通过另一个 ORM 接口(例如 Doctrine)获取的对象,反之亦然。
因此,如果您的其他 ORM 试图巧妙地对数据库进行批量提交,那么您需要在尝试从 Zend_Db 对象中的相同行加载数据之前强制它提交。反之亦然。
也就是说,任何一个类似 ORM 的库中都没有任何东西可以帮助您管理这些情况,因此您需要了解每个 ORM 的行为方式。听起来您需要做大量工作来适应泄漏抽象,并且您最好重写现有的 Zend_Db 代码。
I worked on Zend_Db quite a bit through the 1.0 release of ZF, and I've used Doctrine a little bit too.
There shouldn't be any conflict between Zend_Db and another ORM. However, objects fetched through the Zend_Db interface would have no knowledge of objects fetched through another ORM interface e.g. Doctrine, and vice versa.
So if your other ORM tried to be clever about batching commits to the database, you'd want to force it to commit before trying to load data from the same rows in a Zend_Db object. And likewise in reverse.
That said, there'd be nothing in either ORM-ish library that helps you manage these cases, so it's up to you to know how each ORM behaves. Sounds like you're setting yourself up for a lot of work to accommodate the leaky abstractions, and you'd be better off rewriting your existing Zend_Db code.