public function validate()
    {
        // Check that the parent_id field is valid.
        if ($this->parent_id == 0) {
            throw new NestedHandleException(
                sprintf(
                    'Invalid `parent_id` [%s] in %s',
                    $this->parent_id,
                    get_class($this)
                )
            );
        }

        $query = $this->db->getQuery(true)
            ->select('COUNT(' . $this->db->quoteName($this->getKeyName()) . ')')
            ->from($this->db->quoteName($this->table))
            ->where($this->getKeyName() . ' = ' . $this->parent_id);

        if (!$this->db->setQuery($query)->loadResult()) {
            throw new NestedHandleException(
                sprintf(
                    'Invalid `parent_id` [%s] in %s',
                    $this->parent_id,
                    get_class($this)
                )
            );
        }

        $this->checkParent();

        return $this;
    }
public function validate()
    {
        // Check that the parent_id field is valid.
        if ($this->parent_id == 0) {
            throw new NestedHandleException(
                sprintf(
                    'Invalid `parent_id` [%s] in %s',
                    $this->parent_id,
                    get_class($this)
                )
            );
        }

        $query = $this->db->getQuery(true)
            ->select('COUNT(' . $this->db->quoteName($this->getKeyName()) . ')')
            ->from($this->db->quoteName($this->table))
            ->where($this->getKeyName() . ' = ' . $this->parent_id);

        if (!$this->db->setQuery($query)->loadResult()) {
            throw new NestedHandleException(
                sprintf(
                    'Invalid `parent_id` [%s] in %s',
                    $this->parent_id,
                    get_class($this)
                )
            );
        }

        $this->checkParent();

        return $this;
    }
public function validate ( ) { // Check that the parent_id field is valid. if ( $ this -> parent_id == 0 ) { throw new NestedHandleException ( sprintf ( 'Invalid `parent_id` [%s] in %s' , $ this -> parent_id , get_class ( $ this ) ) ) ; } $ query = $ this -> db -> getQuery ( true ) -> select ( 'COUNT(' . $ this -> db -> quoteName ( $ this -> getKeyName ( ) ) . ')' ) -> from ( $ this -> db -> quoteName ( $ this -> table ) ) -> where ( $ this -> getKeyName ( ) . ' = ' . $ this -> parent_id ) ; if ( ! $ this -> db -> setQuery ( $ query ) -> loadResult ( ) ) { throw new NestedHandleException ( sprintf ( 'Invalid `parent_id` [%s] in %s' , $ this -> parent_id , get_class ( $ this ) ) ) ; } $ this -> checkParent ( ) ; return $ this ; }
Checks that the object is valid and able to be stored.

This method checks that the parent_id is non-zero and exists in the database.
Note that the root node (parent_id = 0) cannot be manipulated with this class.

@return  static  Method allows chaining.

@since   2.0
@throws  \Exception
@throws  \RuntimeException on database error.
@throws  \UnexpectedValueException
Checks that the object is valid and able to be stored .