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;
    }