I have a table called categories. The table holds categories and their sub(subsub)categories...
Its an easy table:
RichardAtHome's answer is the right one. In CakePHP 3.+ you write:
$this->hasMany('Children', [
'className'=>'Category',
'foreignKey'=>'parent_id'
]);
$this->belongsTo('Parent', [
'className'=>'Category',
'foreignKey'=>'parent_id'
]);
and don't forger to use 'contain' in your 'find', e.g.:
$categories = $this->find("all")
->order(...)
->contain(['Children']);