protected function update($connection = null) { // Update nested set keys only if parent id has changed if (isset($this->values['parentId'])) { // Get the "original" parentId before any updates $offset = 0; $originalParentId = null; foreach ($this->tables as $table) { foreach ($table->getColumns() as $column) { if ('parentId' == $column->getPhpName()) { $originalParentId = $this->row[$offset]; break; } $offset++; } } // If updated value of parentId is different then original value, // update the nested set if ($originalParentId != $this->values['parentId']) { $this->updateNestedSet($connection); } } parent::update($connection); return $this; }