开发者

DataMapper ORM vs. Doctrine

开发者 https://www.devze.com 2023-03-23 09:29 出处:网络
I\'m about to start developing a new web a开发者_JAVA技巧pplication in CodeIgniter. In the past, I have used DataMapper ORM for my object mapping needs and have been completely satisfied with it\'s ca

I'm about to start developing a new web a开发者_JAVA技巧pplication 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消