public static function get_relation($competencyid, $relatedcompetencyid) {
        global $DB;

        // Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.
        $relation = new static();
        if ($competencyid > $relatedcompetencyid) {
            $relation->set('competencyid', $relatedcompetencyid);
            $relation->set('relatedcompetencyid', $competencyid);
        } else {
            $relation->set('competencyid', $competencyid);
            $relation->set('relatedcompetencyid', $relatedcompetencyid);
        }

        // We can do it because we have bidirectional relations in the DB.
        $params = array(
            'competencyid' => $relation->get('competencyid'),
            'relatedcompetencyid' => $relation->get('relatedcompetencyid')
        );
        if ($record = $DB->get_record(self::TABLE, $params)) {
            $relation->from_record($record);
        }

        return $relation;
    }