Reference of alias in a query created with Query Builder

I want to use a query builder for this complex generic query.

(new Query)->select([
	"aliasRefId" => ""
        "itemA"      => (new Query)->select(["itA"])
			           ->where(["table_name.itemId" => "aliasRefId"])

The generated query should be:

SELECT as aliasRefId,

	  FROM 	table_name
	  WHERE  table_name.itemId = aliasRefId ) as itemA
	FROM posts

The problem is that I can’t use aliasRefId in that inner select.

Try \yii\db\Expression (or even better: rely on active record and the great query engine)

(new Query)
        'aliasRefId' => '',
        'itemA' => (new Query)
            ->where(['table_name.itemId' => new \yii\db\Expression('[[aliasRefId]]')])