static public function updateOrCreateRecord(array $data) {
        if (empty($data[static::getKeysColumnName()])) {
            throw new \InvalidArgumentException(
                '$record argument does not contain value for key \'' . static::getKeysColumnName() . '\' or its value is empty'
            );
        } else if (!array_key_exists(static::getValuesColumnName(), $data)) {
            throw new \InvalidArgumentException(
                '$record argument does not contain value for key \'' . static::getValuesColumnName() . '\' or its value is empty'
            );
        }
        $conditions = [
            static::getKeysColumnName() => $data[static::getKeysColumnName()]
        ];
        $fkName = static::getInstance()->getMainForeignKeyColumnName();
        if (!empty($fkName)) {
            if (empty($data[$fkName])) {
                throw new \InvalidArgumentException("\$record argument does not contain value for key '{$fkName}' or its value is empty");
            }
            $conditions[$fkName] = $data[$fkName];
        }
        /** @var Record $object */
        $object = static::getInstance()->newRecord()->fromDb($conditions);
        if ($object->existsInDb()) {
            $success = $object
                ->begin()
                ->updateValues(array_diff_key($data, [static::getKeysColumnName() => '', $fkName => '']), false)
                ->commit();
        } else {
            $object
                ->reset()
                ->updateValues($data, false);
            $success = $object->save();
        }
        static::cleanCachedValues(empty($fkName) ? null : $data[$fkName]);
        return $success;
    }