I am trying to convert this sql code into Laminas way ?
Is it possible to set multiple values to Laminas SQL from function ?
SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM categories AS node,
categoies AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.name
ORDER BY node.lft;
It Should be like this but it doesn’t work…
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->columns([
'categoryId',
'name',
'depth' => new Expression("(COUNT(parent.name) - 1)"),
]);
$select->from(new TableIdentifier('categories AS node, categories AS parent'));
$nest = $select->where->nest();
$nest->and->between('node.lft', 'parent.lft', 'parent.rgt');
$nest->unnest();
$select->group(['node.name']);
$select->order(['node.lft']);
Sql output above the code
SELECT
`categories AS node, categories AS parent`.`categoryId`,
`categories AS node, categories AS parent`.`name`,
( COUNT( parent.NAME ) - 1 ) AS `depth`
FROM
`categories AS node, categories AS parent`
WHERE
( `node`.`lft` BETWEEN 'parent.lft' AND 'parent.rgt' )
GROUP BY
`node`.`name`
ORDER BY
`node`.`lft` ASC