Tuesday, January 19, 2010

CakePHP design thoughts

I am working on a project in CakePHP...the first time I have used it. I am finding it very well made, but I am not exactly in the right frame of mind for some of its limitations.

As a SQL guy, I am used to being able to design whatever queries I want and get whatever info I need whenever I need it. The query engine built into CakePHP is decent, but kind of breaks down on more complex queries such as those relating multiple levels of a model. Specifically, it is not happy starting at a parent and joining with a child or grandchild.

This means that if I have relationships such as REGION has many CITIES has many STORES has many PRODUCTS, I cannot simply add a paged query of all products to this REGION or CITY view.  The two mechanisms for doing this--the containable query and the recursive query--break down at these levels. And if PRODUCTS is also a child of PACKAGE_TYPE, it is not really doable.

This doesn't kill the project...it just requires a little cake-like thinking.  Instead of trying to show a fully paged PRODUCT report on my REGION view, I can just show a limited number of products, and provide a link to a view on the PRODUCT level that includes a filter on my region. The query needed at the region level can be coded into and called from the PRODUCT model as a "list the first 20" type of report instead of a "give me everything in multiple pages" type of report.

Without any code samples, this may not be easy to follow...and I am not putting any code samples together now. I guess the point is that Cake is good at providing reports at a child level that include parent level items, but is not so good at providing reports at a parent level that include the child levels.  Just remember that and you won't run into the brick walls I did.

All that said, Cake makes it incredibly easy to put together a CRUD-based application, and I am happy to work within its strictures in exchange for fast creation of projects that can be hosted on nearly any local system or cheap internet provider you can name.

No comments:

Post a Comment