I tried to explain how to do a self join in CakePHP
I use this in my Gallery Model:
var $hasMany = array(
‘Galleries’ => array(
‘className’ => ‘Gallery’,
‘order’ => ‘Galleries.ord ASC’,
‘foreignKey’ => ‘parent_id’));
var $belongsTo = array(
‘Galleries’ => array(
‘className’ => ‘Gallery’,
‘order’ => ‘Galleries.ord ASC’,
‘foreignKey’ => ‘parent_id’));
First, note the ‘Galleries’ (you change that association name for any
other, just dont use the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with [‘child’] and everything. I *heart* CakePHP 🙂
class Category extends AppModel
{
var $name = ‘Category’;
var $belongsTo = array(‘Categories’ => array(‘className’ => ‘Category’,’order’ =>’Category.id DESC’ ,’foreignKey’ => ‘parent_catg’));
}