Interesting presentation about how is the development of this important ORM.
Here it is a really interesting presentation by Jonathan Wage (Doctrine main developer) about the status of Doctrine in the last Zend conference.
Interesting presentation about how is the development of this important ORM.
Here it is a really interesting presentation by Jonathan Wage (Doctrine main developer) about the status of Doctrine in the last Zend conference.
UPDATE: Here is a great comparison for these ORM’s for the 2.x versions. Thanks to @Pati for sharing the link.
A quick comparison for the most 2 well known and best ORM‘s for PHP.
Here we will try to make a quick comparison about the most known ORM for PHP. To help developers to take the right decision when we need to decide what is the best ORM which could best adapt to our projects.
These 2 more used ORM are as the post title mentioned Doctrine and Propel.
Features
Both ORMs have many similar basic features, they support all the usual operations for CRUD (Create, Retrieve, Update and Delete), from create a new record to update existing ones. Also, both can generate the PHP classes for you, Propel based on XML while Doctrine based on YAML, And another cool feature they have is that both support different database engines (like Mysql, Oracle, MSSQL, etc).
Both support data validation and model relationships. Additionally, they support simple inheritance, although in Doctrine is called concrete inheritance. Doctrine supports 2 types of inheritance: Simple, where all the classes have the same columns, and the Aggregation inheritance, where we store an additional value in the table which allows us the automatic instantiate of the right model type when we make a query.
Well, we saw they almost share the same features so far, but the following are features only Doctrine has.
Behaviors: Doctrine supports many “behaviors” for its models, for instance, a Timestampable model will automatically create two columns: created_at and updated_at, where we can store the creation and update dates.
Searching: Doctrine has a fulltext search engine.
Plus, Doctrine supports data fixtures and migrations, caching, events, pagination, commands line interface and so on, and we can say in advanced features Doctrine has an advantage compared with Propel.
Usability
Documentation
One of the most important thing is documentation of course. Without a good documentation is hard to use any library. Until the last year (2009) the Propel documentation was one of the major problem for them, and it’s true they are improving it there still are work to do. In the other hand, the Doctrine documentation is great and the community is continuously improving it. So, about documentation concern, Doctrine is clearly the winner.
Libraries Use
The first task we have to do with both ORMs is to build the model classes. Doctrine allows us to just write a simple YAML file, or just PHP code if you prefer it. The Propel proposal is to write a XML to define our model classes, and in my personal opinion I prefer to deal with YAML instead of XML, so point for Doctrine :-).
Database operations
The basic operations with CRUD are very similar in both ORMs, however, there is a big different when we need to do more advanced queries.
Propel uses a Criteria/Peer proposal:
1 2 3 4 5 6 | <?php $c = new Criteria(); $c->add(UserPeer::ID, 10); //SELECT all "User" models which have 10 as their ID and join all foreign tables. $users = UserPeer::doSelectJoinFoobar($c); |
Doctrine proposal is to use Doctrine_Query and a simple customized SQL named DQL (Doctrine Query Languaje):
1 2 3 4 5 6 | <?php $items = Doctrine_Query::create() ->from('User u') ->leftJoin('u.Foobar') ->where('u.id = ?', 10) ->execute(); |
To set values in our model classes these ORMs utilizes different methods: Doctrine uses magic methods, while Propel generates setters and getters. This feature gives to Propel the advantage of autocompletion in most IDEs.
As conclusion I can say that both ORM are great, but I prefer Doctrine. And, of course, you can put the ‘My opinion’ label to this post.
And in this link you can find a comparison that Symfony made between these 2 ORMs.