PHP Orms: Doctrine VS. Propel

PHP ORMs: Doctrine vs. Propel

I'd go with Doctrine. It seems to me that it is a much more active project and being the default ORM for symfony it is better supported (even though officially the ORMs are considered equal).

Furthermore I better like the way you work with queries (DQL instead of Criteria):

<?php
// Propel
$c = new Criteria();
$c->add(ExamplePeer::ID, 20);
$items = ExamplePeer::doSelectJoinFoobar($c);

// Doctrine
$items = Doctrine_Query::create()
->from('Example e')
->leftJoin('e.Foobar')
->where('e.id = ?', 20)
->execute();
?>

(Doctrine's implementation is much more intuitive to me).

Also, I really prefer the way you manage relations in Doctrine.

I think this page from the Doctrine documentation is worth a read: http://www.doctrine-project.org/documentation/manual/1_2/en/introduction:doctrine-explained

To sum up: If I were starting a new project or had to choose between learning Doctrine and Propel I'd go for Doctrine any day.

Is there a detailed comparison between Propel 2 and Doctrine 2

I'm also during making my decision which PHP ORM to choose and recently I found the following comparison of the main features of Doctrine2 and Propel 2:
Side by side: Doctrine2 and Propel 2.
The comparison is very precise and comprehensive, so surely it can come in handy when making the decision.

Propel or Doctrine; which is better ORM for Symfony 1.4

tl;dr: I used Doctrine for a long time and I will choose Propel if I have to start something new.

This is such a common question that has nearly no good answer. But I will just give you my point of view.

I've worked with Doctrine since the first alpha (and with the old symfony 0.63). We choose Doctrine instead of Propel because Doctrine supported PDO (which is native to PHP) and Propel was still running on Creole (which isn't native). Creole was very slow in comparison to PDO (of course).

Recently, Doctrine added lost of a magic. I mean, you could call getField, findOneByField for everything and it would return what you want. It was something really great instead of having to build your own getter and setter. Magic was really trendy at this time.

Writing query using Doctrine was really easy instead of the painful Criteria and Criterion from Propel, which was really verbose. I was really fan of Doctrine and recommended to everyone to start using it instead of Propel.

Then, Propel switch to PDO as of 1.3 and started to have a nice API to write query, almost the same approach as Doctrine. The main difference was that Propel generate all magic things while Doctrine build on the fly. That's the biggest difference I think.

Propel doesn't have any magic in this code. It generates all getter/setter, join, etc .. when you build your model. Doctrine does every thing when it run the query. That's okay for small to medium project, but it starts to be bigger, it will become a slow solution. And it's great for debugging too, because you find the code in generated classes, you don't have to jump from classes to classes to find the global method that handle this case.

Both ORM use behaviors. I love behaviors. They are handled in different way in Doctrine and Propel. Doctrine still use its magic to handle them where Propel generates everything from the behavior inside the class (one more point from generated class instead of magic one).

As of now, nothing has really changed in Doctrine (to give a shot from the thread you mention) because of Doctrine 2 (which isn't native at all for sf 1.4) since the 1.2.x branch is almost dead (last release are 24/08/2010). Propel is still active, well really active, as you can see on github.

I still work with Doctrine but I've learn a lot from Propel since few years. I've build some personal projects on Doctrine. As of today, I changed my mind, and if I have to start a new project I will do it using Propel.

Few links:

  • Should I choose Doctrine 2 or Propel 1.5/1.6, and why? (on programmers.se)
  • The POV from the Propel lead dev on this choice (in favor to Propel, of course)

Is there a good comparison of Doctrine vs Propel?

I suspect you were around when I asked my question yesterday on freenode?

Most of the time, it's not technical differences that drive people away, but the community. If it doesn't have a vibrant and active community to back it up and answer questions, no matter how much better it is, people will be driven away.

Propel to Doctrine Code Snippet

In your BlogCommentTable.php file, put this method :

public functoion retrieveByPostId($post_id)
{
$q = $this->createQuery('c')
->where('c.blog_post_id = ?', array($post_id))
->orderBy('c.created_at ASC');

return $q->execute();
}

And in your action:

$this->comments = Doctrine_Core::getTable('BlogComment')->retrieveByPostId($request->getParameter('id'));

Benchmarks of PHP ORMs? or Good Test Cases

Doctrine is one of the most well regarded PHP base ones out there. But you can't really benchmark ORMs. All of them will have performance issues when they create a useless JOIN or a bad query, which all of them will do eventually.

In the end, they all just try to create a SQL query for you. How well they do it, is the difference. It's worthwhile to learn SQL if you have more than a few basic tables.

Switch symfony 1.4 from Doctrine to Propel

If you create new (fresh) project...

symfony generate:project xxx --orm=Propel

The easiest thing :)

If you want to change existing project - you have to dig in configuration file and enable propel plugin.

Your configuration file should look similar to:

// config/ProjectConfiguration.class.php
public function setup()
{
$this->enablePlugins('sfPropelPlugin');
...
}

(based on Symfony page, you should dig it next time - especially Practical Symfony)

Propel or Doctrine for ZF integration

Doctrine and Propel are definitely the two best know PHP ORM's among some others.

Doctrine has definitely seen some more love from ZF and there is rumors that Doctrine 2 will play a major role in ZF2, though afaik nothing as been confirmed as of this writing.

Here is some links for you to follow:

  • Integrating Propel with the Zend Framework (2006)
  • Brandon Savage: The Adventures Of Merging Propel With Zend Framework

and

  • Ruben Vermeersch: Integrating Zend Framework and Doctrine 1.x
  • Matthew Weier O'Phinney: Autoloading Doctrine and Doctrine entities from Zend Framework
  • Doctrine 2 and Zend Framework first date

Also see these two questions that have additional information and links:

  • Zend Framework 1.9 and Doctrine Integration
  • Integrate Doctrine with Zend Framework 1.8 app

Should not be hard to find many more for Doctrine.

EDIT very nice one from Phil's comment:

  • Zend Framework / Doctrine integration suite


Related Topics



Leave a reply



Submit