/**
* @var bool
* whether to automatically set operation to OPERATION_MAKE_ROOT
* on saving new records, so you could use
* $model->save();
* instead of
* if ($model->isNewRecord) {
* $model->makeRoot();
* } else {
* $model-save();
* }
*/
public $makeRootOnInsert = false;
then in before insert
public function beforeInsert()
{
if ($this->makeRootOnInsert && !in_array($this->operation, [
self::OPERATION_MAKE_ROOT,
self::OPERATION_PREPEND_TO,
self::OPERATION_APPEND_TO,
self::OPERATION_INSERT_BEFORE,
self::OPERATION_INSERT_AFTER,
])) {
$this->operation = self::OPERATION_MAKE_ROOT;
}
/* ... */
}
then in before insert