Welcome to Delicate template
Header
Just another WordPress site
Header

Why I switched to Doctrine

March 20th, 2008 | Posted by Michaël in ICT | Symfony | Web Development

As I said in my previous post, I would tell more about why I switched to Doctrine. I mainly started to think about the idea when I first heared that we were going to start a new project in Symfony at work. The lead developer decided to go for Doctrine ORM instead of Propel. So I wanted to know why go went for Doctrine. I allready knew that Doctrine is way faster then Propel 1.2 and it has more possibilities, but I just wanted to hear it from him. And I have to admit, he had good arguments.

The verbosity of the Doctine code is way better then Propel. The model mappings (in line of XML files or YAML) are bigger for Propel then for Doctrine, and in Doctrine you can do everything in PHP instead of using external files (consolidated code is a huge plus).

The API of Propel is also “time-consuming”. Check the following Propel code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$c = new Criteria();
 
$cton1 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Leo");
 
$cton2 = $c->getNewCriterion(AuthorPeer::LAST_NAME,
array("Tolstoy",  "Dostoevsky", "Bakhtin"), Criteria::IN);
 
$cton1->addOr($cton2);
 
// add to Criteria
 
$c->add($cton1);
 
$authors = AuthorPeer::doSelect($c);

with this Doctrine code:

1
2
3
4
5
$authors = $conn->query("
 
FROM Author a WHERE a.first_name = ? OR a.last_name IN ?
 
",array('Leo',array("Tolstoy", "Dostoevsky", "Bakhtin"));

Propel doesn’t support his own query definition language like Doctrine, so every query has to be done through time-consuming API calls (and Doctrine also supports a object oriented API, so it is available if you need it). But it gets a lot more uglier if you when you need associations and eager loading in your queries, what can be run smoothley in Doctrine.

Doctrine supports 3 types of inheritance that you find back in Hibernate, where Propel is only limited in single-table-inheritance. This can be very usefull in the implementation of complex systems.

Doctrine support a sort of mixins (this at the act_as_* plugins of ActiveRecord), in a language that doesn’t support mixins :) . Even think about the “event listeners” like the before_save etc methods in ActiveRecord. (long live Rails right )

Doctine even supports migrations, and in the near future, they even will have automatic migrations (change the model definition, run auto-migrate and the DB is updated).

Some other nice features are full text searching, query/result caching, magic finders ($table->findOneByName), etc.

Doctrine is build in a logical way, the pragmatic use of ActiveRecord mixed with the power of Hibernate.

So be honost, I someone would tell you all the above, wouldn’t you just make the switch immediately?!?

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

5 Responses

  • Arthur says:

    The only thing that has held me back from switching is the Symfony integration. When using Doctrine, you can’t use useful stuff like the object_for_* helpers or the admin generator.

  • D@ Mick says:

    To be honost, I haven’t realy used the admin generator of Symfony yet. In none of my projects to be exacly. What is the true advantage of the admin generator? I just design the forms manualy and it doesn’t take that mutch time right?

  • Klemens says:

    Thanks for the article!

    There are no object helpers for Doctrine?

  • Niklas says:

    Hi,
    your experience on Propel seems to very outdated..

    In Propel 1.5 you query the database like:

    $foos = FooQuery::create()->filterByBar(‘MyBarValue’)->filterByStatus(array(1,4,6))->find();

    This uses code generation and performs a lot faster than doctrine..

  • D@ Mick says:

    Hi Niklas

    I don’t know if you checked the date, but I wrote that blogpost on March 20 in 2008, that’s almost 2,5 years ago. So, yea, it is normal dat my experience mentioned in this blogpost is outdated.



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">