attractive, usable web applications


Richard's Blog - Design, coding and life in Japan

Richard

Object Relational Mappers in CakePHP, CI and other frameworks

 I am currently doing a project in CakePHP which I generally like, it is far from perfect but it is heading in the direction and is getting even better with 1.3 nearly being released. It also happens to be one of the most popular open source web frameworks in Japan which is a good reason to get using it.

My moan is about the Object Relational Mapper (ORM),

I was frustrated that I couldn't just use objects in associations like in Rails. I am so used to doing something like

@user = User.new
@user.posts = Post.new

Nice and easy! in Cake I would have to add create both objects from their model, work out the id for the posts object (meaning I have to save it first). In rails  you can even get the id by calling

Post.new.id

then when it saves it will pass the id when needs to. Although the power and flexibility of the Ruby object makes it hard for PHP to catch up, it is by no means impossible with Doctrine (Have yet to see a similarly powerful PHP ORM). Doctrine is an attempt to bring to the PHP world which we have with Hibernate in Java which is also a fantastic ORM which deals with objects and not arrays. Which is what the problem really boils down to. Data needs to be an object and mappers need to work out how these objects associate with each other cleanly and simply.

Cake is half way there but not the whole way yet. Miles better than Code Igniters active record which is almost a joke, but at least you can use Doctrine in Code Igniter which saves it.

I really think these guys should think about offering support for Doctrine, I know I heard promises of dealing with real objects in Cake's ORM but wouldn't it be easier to leave the job to Doctrine like in Symfony and then you can focus on the parts of Cake which do shine like components and views etc.

Tags:

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Recent Blog Posts