I am using the tree behavior and when I query via ->find(‘threaded’, …) – as expected – I get the tree back.
But I want additional joins happen, so something like:
$data = $this->Category->find('threaded', array(
'joins' => array(
array('table' => 'videos',
'alias' => 'Video',
'type' => 'LEFT',
'conditions' => array(
'Category.id = Video.category_id',
)
)
)
));
Category hasMany Video, but Video is not a tree, just related.
Can I use the threaded query for that?
To produce the “threaded” output Cake 1) calls a find(‘all), then 2) puts the resulting array through Set::nest() function.
So just get your output using a standard find + your custom joins, then just use the
Set::nest(NB:
Hashhas replacedSetin Cake 2, but Cake still usesSetinternally. Both will work for now.Hash::nest)So if you take a look at Cake’s
model.php, the nest function is called like so:Use that as a template for your call. For your data it would look something like: