Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Root on Insert param #107

Open
konkov-alexey opened this issue Nov 16, 2016 · 0 comments
Open

Make Root on Insert param #107

konkov-alexey opened this issue Nov 16, 2016 · 0 comments

Comments

@konkov-alexey
Copy link

konkov-alexey commented Nov 16, 2016

    /**
     * @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;
        }
        /* ... */
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant