Skip to content

Incorrect typecasting in some cases when select uses equal names #1150

@vjik

Description

@vjik

Description

public function testWithTypecastingEdgeCase(): void
{
    $this->dropTable('test');

    $db = $this->getSharedConnection();
    $db->createCommand()->createTable('test', [
        'id' => PseudoType::PK,
        'json_col' => ColumnBuilder::json(),
    ])->execute();
    $db->createCommand()->insert('test', ['json_col' => ['a' => 1, 'b' => 2]])->execute();

    $query = $db
        ->select([
            't1.id as json_col',
            't2.json_col',
        ])
        ->from('test t1')
        ->innerJoin('test t2', 't2.id = t1.id');

    $this->assertSame(['json_col' => '{"a":1,"b":2}'], $query->one());

     // Currently, `['json_col' => 0]` is here
    $this->assertSame(['json_col' => ['a' => 1, 'b' => 2]], $query->withTypecasting()->one());
}

Package version

2.0.0

PHP version

any

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions