I decided to use nested sets model. My table has columns: id, name, lft, rgt, parent_id
My function to add new node:
public function actionAdd($parent = null)
{
$model = Menu::find()->where(['id' => $parent])->one();
if ( $model )
{
$connection = \Yii::$app->db;
$rgt = $model->rgt;
$connection->createCommand('UPDATE category SET rgt = rgt+2 WHERE rgt > '.$rgt)->execute();
$connection->createCommand('UPDATE category SET lft = lft+2 WHERE lft > '.$rgt)->execute();
}
else
{
$rgt = 1;
}
$m2 = new Menu;
$m2->lft = $rgt;
$m2->rgt = (int)$rgt + 1;
$m2->parent_id = $parent;
$m2->name = 'test'.$rgt;
$m2->save();
}
Nodes are added in various locations inconsistent with parent_id. My question is what am I doing wrong ?
Query to show:
$sql = "SELECT node.*, (COUNT(parent.id) - 1) AS depth
FROM category AS node, category AS parent
WHERE (node.lft BETWEEN parent.lft AND parent.rgt)
GROUP BY node.id
ORDER BY node.lft";
I'll just add that as sort with jQuery plugin ( http://mjsarfatti.com/sandbox/nestedSortable ) and ajax store. Its display good.
My jQuery code: http://pastebin.com/raw.php?i=q7LALNTP
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I think I'm missing an obvious answer. I have an array of arrays, like this.
Well, i'm modifying a board system, and i have this datetime format:.