db icon indicating copy to clipboard operation
db copied to clipboard

`Query::leftJoin` - a simpler way to quote join column?

Open arogachev opened this issue 9 months ago • 3 comments

use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Query\Query;

/**
 * @var ConnectionInterface $database 
 * @var string $tableName
 * @var string $childrenTableName
 */
$quoter = $database->getQuoter();
$quotedJoinColumn = $quoter->quoteTableName($tableName)  . '.' . $quoter->quoteColumnName('name');
$rawItems = (new Query($database))
    ->select($tableName . '.*')
    ->from($tableName)
    ->leftJoin($childrenTableName, [$childrenTableName . '.child' => new Expression($quotedJoinColumn)])
    ->all();

arogachev avatar Sep 22 '23 10:09 arogachev