I currently have two models: Product and Service. Both share the same table structure and the same methods. However, when I update one method, I’ll have to do the same with the other model. And it gets messy, not to mention I’m causing redundancy and it’s not the best practice available.
I know the models can be linked to the same table, so I’ll just have to add a $useTable = 'stuff' in the model and I could add a type field. However, I can’t figure out how to create a “parent” model since each model extends the AppModel.
To be fair, I know almost next to nothing about OOP, so I could be missing something very obvious and simple.
What I would do without knowing how to extend two children (Product and Service) to a parent (Stuff) would be something like:
$this->Stuff->type = 'product';
$products = $this->Stuff->findAvailable();
But I bet there’s a much simpler, cleaner approach.
Thanks.
Use a Behavior. As stated in the cookbook:
http://book.cakephp.org/view/1071/Behaviors
The link should give you a pretty good idea of where to start.