Incorrect typecasting in some cases when select uses equal names
Open
Nobody has claimed this yet.
type:bug
- Dominant language
- PHP
- Stars
- 216
- Forks
- 51
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 2
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use testWithTypecastingEdgeCase as the reproduction entry point, then trace withTypecasting() through the query result typecasting path for duplicate selected names. Run the database test suite containing this case and compare the two assertions for the aliased id and JSON column. Done means the untyped result remains the JSON string and the typed result preserves the expected associative array when both selections are named json_col.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100