public static function getLastInsertId(string $keyName = null)
    {
        if (static::$autoIncrement) {
            if (is_string(static::$autoIncrement)) {
                $keyName = static::$autoIncrement;
            } else if (is_string(static::$primaryKey)) {
                $keyName = static::getTableName() . '_' . static::$primaryKey . '_seq';
            }

            return static::getAdapter()->getLastInsertId($keyName);
        } else {
            throw new Exception('Can not get last insert ID when model ' . get_called_class() . ' doesn\'t have auto_increment field');
        }
    }