Cake\ORM\Table::findThreaded PHP Method

findThreaded() public method

Values belonging to a parent row based on their parent_id value will be recursively nested inside the parent row values using the children property You can customize what fields are used for nesting results, by default the primary key and the parent_id fields are used. If you wish to change these defaults you need to provide the keys keyField, parentField or nestingKey in $options: $table->find('threaded', [ 'keyField' => 'id', 'parentField' => 'ancestor_id' 'nestingKey' => 'children' ]);
public findThreaded ( Query $query, array $options ) : Query
$query Query The query to find with
$options array The options to find with
return Query The query builder
    public function findThreaded(Query $query, array $options)
    {
        $options += ['keyField' => $this->primaryKey(), 'parentField' => 'parent_id', 'nestingKey' => 'children'];
        if (isset($options['idField'])) {
            $options['keyField'] = $options['idField'];
            unset($options['idField']);
            trigger_error('Option "idField" is deprecated, use "keyField" instead.', E_USER_DEPRECATED);
        }
        $options = $this->_setFieldMatchers($options, ['keyField', 'parentField']);
        return $query->formatResults(function ($results) use($options) {
            return $results->nest($options['keyField'], $options['parentField'], $options['nestingKey']);
        });
    }