Zend Framework + Doctrine 1.2

Posted by Scato Eggen on 21 May 2010

Tag(s): Databases, Webapplicaties, Artikel, Open Source

Some time ago I came across a post about how Zend Framework and Doctrine can be easily integrated, so I decided to check it out.

Doctrine is supposed to be an Object Relational Mapper, so I decided to give it the toughest problem I could think of: a tree based on an abstract node class... Node implements the child/parent node logic. Subclasses like Folder and Page implement more specific logic. Node is abstract, Folder and Page are concrete.

Zend Framework follows a "use-at-will" architecture, so I should be able to use Doctrine instead of Zend_Db_Table without any hassle.

Doctrine

The first problem with Doctrine 1.2 is the lack of support for class table inheritance. So I experimented with the other schemes and ended up with column aggregation (also called single table inheritance). Then I added some entries to the database and dumped them to my data fixture. But not all data fixtures can be imported. Because of all the references between objects, it's hard to tell which object should be inserted first. On top of that, Doctrine adds foreign key constraints for you, but leaves them on when it clears the database. Not a very wise move... I ended up rewriting all my data fixtures. But then it finaly worked.

Another problem with Doctrine 1.2 is that it interferes with your model classes. (I also get anoyed every time someone calls model object models. There's only one model.) It also has a hard time with directory structures. And there I thought everyone knew PEAR naming conventions. Luckily there's an option you can enable so it does use this convention. Sadly you have to do it by hand. It's a protected property and there's no method to change it.

The worst part is that Doctrine 1.2 is not really a data mapper. Every model class inherits from a generated base class. Base classes inherit from model classes if you want them, though.

Zend Framework

Luckily, Zend Framework does what it does best: what you ask it to do and nothing more... I can use view scripts, controllers and Zend_Form to display and edit model objects. None of them assumes I use Zend_Db_Table. I can even use Zend_Config for configuring Doctrine, but since Doctrine itself was rather disappointing I didn't bother.

Conclusion

Doctrine 1.2 doesn't live up to my expecations. An Object Relational Mapper should not have to interfere with my model classes.

Doctrine 2.0 is finaly in beta. I'm very eager to find out more. I'm also very curious if I will manage to make it work. Last time I tried it was in alpha and it gave all sorts of weird error messages.

Post a comment:

Name:
E-mail*:
Comment:
*optional, will not be published.