How to convert from Propel to Doctrine

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

This is a great discussion:

1. While it’s true that Doctrine has Table classes rather than Peer
classes, you can continue to follow the convention of putting static
methods in the Table classes if you feel like it, and this will save
you some time. You can also write non-static methods, which is handy
because you can create a query conveniently with $this->createQuery().
If you take that approach, the calling code should use
Doctrine::getTable(‘modelClassName’)->getAllWiggles() to call those
methods, rather than modelClassNameTable::getAllWiggles().
2. In most ways writing queries with Doctrine cascading methods and/or
DQL is vastly less annoying than working with the Criteria class.
However you can nest Criteria objects deeply if you need to, as
combinations of ORs and ANDs. Doctrine has addWhere(), but doesn’t
allow you to make a complex tree that translates to parentheses in the
final SQL.
On the other hand, Doctrine doesn’t HAVE to do that, because you can
just write DQL:
Doctrine_Query::create()->from(‘modelClassName m’)->where(‘m.x < ? AND (m.y < ? OR m.name = ?), array(50, 100, "Bob")); Still, if you are building up query criteria by calling several methods that you reuse in a variety of queries, and simply ANDing or ORing all of the clauses together without nesting is not sufficient for you, then you have to build DQL strings by concatenation. In practice I find this is very rarely necessary. Another annoyance is that while Doctrine does have addWhereIn() for easily building an IN query (such as checking whether the ID is one of a list of IDs), it does not have a convenient way to build an IN clause deep inside a complex DQL query that requires parentheses like the one above. So you occasionally do have to write something like: 'm.x < ? AND (m.y < ? OR m.id IN (' . implode(", ", $myIds) . '))'; Which leaves something to be desired. Propel criteria are good at that one, at least once you get comfortable understanding (and typing) a nested tree of them. However Doctrine's superior support for joining tables in complex ways often eliminates the need for IN clauses. One more note about writing IN clauses that everybody seems to miss... if $myids is an empty list, MySQL will produce a syntax error. "Empty equals evil and scary and different" is an annoying property that both MySQL and PHP tend to display in many situations. Simply skipping the IN clause completely would always match everything, when of course you should match nothing. A simple and correct workaround is to replace the entire IN clause with FALSE when the list is empty.

Post external references

  1. 1
    http://groups.google.com/group/symfony-users/browse_thread/thread/f0df7c0db703faf
Source