Skip to content

Commit bad37ce

Browse files
committed
fix: keep nested object paths and main-table FOJ identity
1 parent 66b739d commit bad37ce

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎src/Database/Adapter/SQL.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,7 +3489,7 @@ private function qualifyDottedAttribute(string $attribute, array $aliasSet, arra
34893489
return $this->filter($prefix).'.'.$this->filter($this->getInternalKeyForAttribute($name));
34903490
}
34913491

3492-
return $this->filter($this->getInternalKeyForAttribute($attribute));
3492+
return $attribute;
34933493
}
34943494

34953495
/**
@@ -4209,8 +4209,9 @@ private function remapRow(array &$row): void
42094209
$public = Storage::attribute($bare);
42104210
$dotted = $prefix.'.'.$public;
42114211
$identity = isset($identityColumns[$bare]);
4212+
$mainAlias = $prefix === Query::DEFAULT_ALIAS;
42124213

4213-
if ($bare !== '' && ! $identity && ! \array_key_exists($bare, $row)) {
4214+
if ($bare !== '' && ! \array_key_exists($bare, $row) && (! $identity || $mainAlias)) {
42144215
$row[$bare] = $row[$key];
42154216
}
42164217
if (! \array_key_exists($dotted, $row)) {

‎tests/unit/SQLFindTest.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public function testEmulatesFullOuterJoinRemapsQualifiedUnionColumns(): void
198198
'table_main._createdAt' => '2020-01-01 00:00:00.000',
199199
'table_main._updatedAt' => '2020-01-01 00:00:00.000',
200200
'table_main.name' => 'Alice',
201+
'orders._uid' => 'order1',
202+
'orders._permissions' => '["read"]',
201203
'foj_ord_0' => 1,
202204
],
203205
]);
@@ -220,6 +222,40 @@ public function testEmulatesFullOuterJoinRemapsQualifiedUnionColumns(): void
220222
$this->assertSame('Alice', $results[0]->getAttribute('name'));
221223
$this->assertSame(false, $results[0]->isSet('foj_ord_0'));
222224
$this->assertSame(false, $results[0]->isSet('table_main._uid'));
225+
$this->assertSame('order1', $results[0]->getAttribute('orders.$id'));
226+
$this->assertSame(['read'], $results[0]->getAttribute('orders.$permissions'));
227+
$this->assertSame(false, $results[0]->isSet('orders._uid'));
228+
}
229+
230+
public function testQualifyDottedAttributeKeepsNestedObjectPaths(): void
231+
{
232+
$adapter = new MySQL($this->getMockBuilder(\PDO::class)->disableOriginalConstructor()->getMock());
233+
$method = new ReflectionMethod(MySQL::class, 'qualifyDottedAttribute');
234+
235+
$aliasSet = [
236+
Query::DEFAULT_ALIAS => true,
237+
'orders' => true,
238+
];
239+
$mainAttributes = [
240+
'meta.score' => true,
241+
];
242+
243+
$this->assertSame(
244+
'metascore',
245+
$method->invoke($adapter, 'meta.score', $aliasSet, $mainAttributes)
246+
);
247+
$this->assertSame(
248+
'orders.email',
249+
$method->invoke($adapter, 'orders.email', $aliasSet, $mainAttributes)
250+
);
251+
$this->assertSame(
252+
'orders._uid',
253+
$method->invoke($adapter, 'orders.$id', $aliasSet, $mainAttributes)
254+
);
255+
$this->assertSame(
256+
'profile.user.email',
257+
$method->invoke($adapter, 'profile.user.email', $aliasSet, $mainAttributes)
258+
);
223259
}
224260

225261
/**

0 commit comments

Comments
 (0)