DataMapper ORM 与 Doctrine
我即将开始在 CodeIgniter 中开发一个新的 Web 应用程序。过去,我曾使用 DataMapper ORM 来满足我的对象映射需求,并且对其功能完全满意。然而,我的满足感只限于我的知识范围。因此,我正在考虑切换到 Doctrine。
我查看了 Doctrine 的文档 - 看来你必须相当广泛地定义你的模型;添加 getter 和 setter、提供方向引用、提供映射等。乍一看,与 DataMapper ORM 直接比较,这似乎是巨大的开销。
有使用这两种 ORM 经验的人能否评论一下是什么驱使您从一种 ORM 转向另一种?
Doctrine 实现了哪些 DataMapper ORM 无法实现的关键功能?
手动模型定义是倒退还是前进?我认为这是一个性能问题。
I'm about to start developing a new web application in CodeIgniter. In the past, I have used DataMapper ORM for my object mapping needs and have been completely satisfied with it's capabilities. However, my satisfaction only goes as far as my knowledge. Hence, I am considering switching to Doctrine.
I looked into Doctrine's documentation - it appears you have to define your models quite extensively; add getters and setters, provide direction references, provide mapping, etc. At first glance, this appears as tremendous overhead in direct comparison to DataMapper ORM.
Can anybody with experience with both ORMs comment on what drove you from one to the other?
What critical functionality does Doctrine acheive that DataMapper ORM cannot?
Is the manual model definition a step backwards or forwards? I presume it's a performance thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataMapper ORM 和 Doctrine 遵循一组完全不同的约定。 DataMapper ORM(足够令人困惑)不是数据映射器,而是活动记录实现。这意味着您的模型类与 ORM 库紧密集成。您的模型建立在内置 DataMapper 模型的基础上。您可以免费获得很多魔力,但作为交换,您可以将模型与 DataMapper ORM 结合起来。
另一方面,Doctrine 使用真正的数据映射器模式。它的模型是普通的旧 PHP 对象。他们没有外部依赖性。 Doctrine 可以获取任何旧的 PHP 对象,将其存储在数据库中,然后再次检索它。它的模型根本不与 ORM 耦合。
您在 Doctrine 文档中读到的有关 getter、setter、关系完整性等的内容,它们只是良好的 OO 开发实践。它们不是 Doctrine 的要求,但它们让你的生活更轻松。您也应该将它们用于您的 DataMapper ORM 模型!如果您愿意,您可以在 Doctrine 模型上使用神奇的 getter 和 setter,甚至只是简单的旧公共属性。仅仅因为教义说你不应该这样做,并不意味着你不能这样做。 Doctrine 会很乐意将您的模型与公共属性一起使用,但有一些注意事项。就这样。
DataMapper ORM and Doctrine follow a completely different set of conventions. The DataMapper ORM is (confusingly enough) not a data mapper but an active record implementation. That means that your model classes are tightly integrated with the ORM library. Your models build on the built-in DataMapper models. You get a lot of magic for free but in exchange you marry your models to the DataMapper ORM.
Doctrine on the other hand uses a true data mapper pattern. It's models are plain old PHP objects. They have no external dependencies. Doctrine can take any old PHP object, store it in a database and later retrieve it again. It's models are not coupled with the ORM at all.
The things you read about in the Doctrine documentation about getters, setters, relational integrity, etcetera, they are just good OO development practices. They are not a requirement for Doctrine but they make your life easier. You should be using them for your DataMapper ORM models too! If you want, you could use magic getters and setters or even just plain old public properties on your Doctrine models. Just because Doctrine says that you shouldn't do it does not mean that you cannot do it. Doctrine will happily use your models with public properties, but there are some caveats. That's all.