
attractive, usable web applications
Richard's Blog - Design, coding and life in Japan
Object Relational Mappers in CakePHP, CI and other frameworks
Submitted by Richard on Mon, 03/22/2010 - 21:24I 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:
Recent Blog Posts
- Why you should use Rails 3 and not Django 5th Sep 10, 12:28
- Doctrine 2 and why you should use it! 29th Jul 10, 15:23
- How to localize your main blog listing page using Drupal 26th Jun 10, 11:46
- Creating Rails like template helpers in Django 24th Jun 10, 22:01
- Error: No module named messagesdjango.contrib.contenttypes 22nd Jun 10, 22:00
Post new comment