protected function validate_parentid($value) {

        // Check that the parent exists. But only if we don't have it already, and we actually have a parent.
        if (!empty($value) && !$this->newparent && !self::record_exists($value)) {
            return new lang_string('invaliddata', 'error');
        }

        // During update.
        if ($this->get('id')) {

            // If there is a new parent.
            if ($this->beforeupdate->get('parentid') != $value && $this->newparent) {

                // Check that the new parent belongs to the same framework.
                if ($this->newparent->get('competencyframeworkid') != $this->get('competencyframeworkid')) {
                    return new lang_string('invaliddata', 'error');
                }
            }
        }

        return true;
    }