public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        $parent = $this->Parent();
        if ($parent->exists() && !$parent instanceof Blog) {
            $first_blog = Blog::get()->first();
            if ($first_blog) {
                $this->ParentID = $first_blog->ID;
            }
        }
        $this->extend('onBeforeWrite');
    }
public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        $parent = $this->Parent();
        if ($parent->exists() && !$parent instanceof Blog) {
            $first_blog = Blog::get()->first();
            if ($first_blog) {
                $this->ParentID = $first_blog->ID;
            }
        }
        $this->extend('onBeforeWrite');
    }
public function onBeforeWrite ( ) { parent :: onBeforeWrite ( ) ; $ parent = $ this -> Parent ( ) ; if ( $ parent -> exists ( ) && ! $ parent instanceof Blog ) { $ first_blog = Blog :: get ( ) -> first ( ) ; if ( $ first_blog ) { $ this -> ParentID = $ first_blog -> ID ; } } $ this -> extend ( 'onBeforeWrite' ) ; }
Ensure the Parent is a Blog, if not move it to the first blog
Ensure the Parent is a Blog if not move it to the first blog