Skip to content

Commit 296beba

Browse files
cconard96cedric-anne
authored andcommitted
Fix column remap for joined properties
1 parent cbe7cff commit 296beba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Api/HL/Search.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ private function __construct(array $schema, array $request_params)
7676
private function getSQLFieldForProperty(string $prop_name): string
7777
{
7878
$prop = $this->flattened_properties[$prop_name];
79+
$is_join = str_contains($prop_name, '.');
7980
$sql_field = $prop['x-field'] ?? $prop_name;
80-
if (!str_contains($sql_field, '.')) {
81+
if (!$is_join) {
82+
// Only add the _. prefix if it isn't a join
8183
$sql_field = "_.$sql_field";
84+
} else if ($prop_name !== $sql_field) {
85+
// If the property name is different from the SQL field name, we will need to add/change the table alias
86+
// $prop_name is a join where the part before the dot is the join alias (also the property on the main item), and the part after the dot is the property on the joined item
87+
$join_alias = explode('.', $prop_name)[0];
88+
$sql_field = "{$join_alias}.{$sql_field}";
8289
}
8390
return $sql_field;
8491
}

0 commit comments

Comments
 (0)