
front and back-end web development, Leeds, UK
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
- Testing controllers in Lithium 2nd Feb 12, 18:19
- Practical Internationalization in Lithium 31st Dec 11, 02:06
- Using OAuth in Lithium 30th Dec 11, 23:47
- How to add your own Tokens from CCK fields in Druapl 7 17th Jun 11, 04:49
- Weaving Lithium #li3 into a legacy PHP application incrementally 5th Oct 10, 11:54