Tag Archive for 'CakePHP'

HowTo: CakePHP 1.2 Model ORM Inheritance Hack

[Edit: Fixed a bug in model to filter by subtype]
[Edit: again]
[Edit: Oops. I forgot to add the cvar function!]
[Edit: Fixing more bugs in the query generation. Add DboSource mod. Give me a break. it's my first week using CakePHP]

The Problem

Simple CakePHP ORMCakePHP is fairly good as an ORM Framework. You create database tables and it automagically maps them into Model classes for use in a nice MVC application. And, in most cases, this is just fine for most database tables. Relations get mapped and linked, things are peachy. But Cake has it’s shortcomings. The ORM in Cake is nowhere near as capable as say, Hibernate, and in particular (at least as of 1.2r5875) Cake’s Model class mapping does not support inheritance.Inheritance ORM Case
Hopefully Cake developers realize this is a deal breaker for a lot of people. For one of my own projects at least, I needed ORM inheritance and for reasons I won’t go into here, I had to use Cake.

The Solution

What I came up with is very much a hack. It involves modifying model.php (internals of Cake proper). If you’re doing a one off project, this is fine, but be warned that if you implement this hack, upgrading cake won’t be a simple matter of moving your app directory.
Anyhow, it works like this… Continue reading ‘HowTo: CakePHP 1.2 Model ORM Inheritance Hack’