PHP Object/Relational Mapper

May 20, 2008 at 4:36 am Leave a comment

In the past I used to write my own object relational mapping tools. This was time consuming and cumbersome but it afforded me the maximum amount of freedom to implement my domain model designs exactly as I envisioned them. However, as project deadlines began to get shorter and shorter, I just didn’t have the time to devote to writing a custom object model for each project — no matter how much the project needed it. Luckily a colleague of mine turned me on to Propel, an open source tool that will generate a rich object model. All you need to do is create an XML file based on your database and Propel’s runtime generator will generate an object model that maps nicely to your database. In a matter of minutes (or for a really complex project, hours) I can have a fully functional, bug free, object model to begin working with.

As if that wasn’t good enough, Propel also contains a class called Criteria. This class is used as an OO API for writting SQL queries — from simple to increasingly complex. This is something that I’ve always meant to write for myself but just never had the time to do it right. The Criteria class is quite effective and easy to use once you get comfortable with it. Unfortunately the Propel API documentation isn’t the greatest and like me, you’ll probably spend a while reading through the code. That is if you want more than a peripheral understanding of the Criteria class.

The only downside about Propel is that in a lot of ways it’s missing functionality that I was able to write into my custom object model. Since I don’t have access to editing the base Propel classes, any functionality that I want to apply to the entire domain model has to be hard coded into each class. This can become pretty cumbersome and isn’t very reusable among different projects. Luckily Propel is open-source, so the solution here is to become involved in the Propel community and attempt to offer my suggested extensions and offer my help in future development.

My biggest problem with Propel right now, is that collections of objects are returned as an array. I’m surprised that an ORM tool would not have a collection class that allows an OO interface for dealing with an manipulating collections of objects. Especially since the SPL has a great set of classes for implementing iterators and various collections. One of the main Propel extensions that I’ve been using for my projects has been a class that models a collection of objects. It extends the SPL ArrayObject class and implements an interface based on the Java.util.Collection interface.

I’ll post a little code snippet shortly…

Advertisement

Entry filed under: Uncategorized. Tags: .

First article down! Propel: BaseObject Collection

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

May 2008
S M T W T F S
« Mar   Jun »
 123
45678910
11121314151617
18192021222324
25262728293031

Most Recent Posts


Follow

Get every new post delivered to your Inbox.