src/db/orm/Worker.php
private function translateQuery($sql) {
        // model name pattern: ":User" => "t_user" (will also convert matching names in literals and comments)
        $pattern = '/[^:]:([a-z_]\w*)\b/i';
        if (preg_match_all($pattern, $sql, $matches, PREG_OFFSET_CAPTURE)) {
            $namespace = strLeftTo($this->entityClass, '\\', -1, true, '');

            foreach (\array_reverse($matches[1]) as $match) {
                $modelName = $match[0];
                $offset    = $match[1];
                $className = $namespace.$modelName;
                if (is_a($className, PersistableObject::class, true)) {
                    /** @var DAO $dao */
                    $dao   = $className::dao();
                    $table = $dao->getMapping()['table'];
                    $sql   = substr_replace($sql, $table, $offset-1, strlen($modelName)+1);
                }
            }
        }
        return $sql;
    }
private function translateQuery($sql) {
        // model name pattern: ":User" => "t_user" (will also convert matching names in literals and comments)
        $pattern = '/[^:]:([a-z_]\w*)\b/i';
        if (preg_match_all($pattern, $sql, $matches, PREG_OFFSET_CAPTURE)) {
            $namespace = strLeftTo($this->entityClass, '\\', -1, true, '');

            foreach (\array_reverse($matches[1]) as $match) {
                $modelName = $match[0];
                $offset    = $match[1];
                $className = $namespace.$modelName;
                if (is_a($className, PersistableObject::class, true)) {
                    /** @var DAO $dao */
                    $dao   = $className::dao();
                    $table = $dao->getMapping()['table'];
                    $sql   = substr_replace($sql, $table, $offset-1, strlen($modelName)+1);
                }
            }
        }
        return $sql;
    }
private function translateQuery ( $ sql ) { // model name pattern: ":User" => "t_user" (will also convert matching names in literals and comments) $ pattern = '/[^:]:([a-z_]\w*)\b/i' ; if ( preg_match_all ( $ pattern , $ sql , $ matches , PREG_OFFSET_CAPTURE ) ) { $ namespace = strLeftTo ( $ this -> entityClass , '\\' , - 1 , true , '' ) ; foreach ( \ array_reverse ( $ matches [ 1 ] ) as $ match ) { $ modelName = $ match [ 0 ] ; $ offset = $ match [ 1 ] ; $ className = $ namespace . $ modelName ; if ( is_a ( $ className , PersistableObject :: class , true ) ) { /** @var DAO $dao */ $ dao = $ className :: dao ( ) ; $ table = $ dao -> getMapping ( ) [ 'table' ] ; $ sql = substr_replace ( $ sql , $ table , $ offset - 1 , strlen ( $ modelName ) + 1 ) ; } } } return $ sql ; }
Translate entity names in a SQL query into their DBMS table counterparts. At the moment this translation requires all
entity classes to be in the same namespace as the worker's entity class.

@param  string $sql - original SQL query

@return string - translated SQL query
Translate entity names in a SQL query into their DBMS table counterparts . At the moment this translation requires all entity classes to be in the same namespace as the worker s entity class .