-
-
Notifications
You must be signed in to change notification settings - Fork 271
Closed
Description
Hello, I get an SQL error due to duplicate table name in qualified foreign key column:
I simplified code to get the root cause, here is my inspection:
public function resolve($root, $args, SelectFields $fields)
{
return $fields->getSelect();
}It gives me:
[
"games.id",
"games.name",
"games.games.owner_id"
]While I expected:
[
"games.id",
"games.name",
"games.owner_id"
]To get the SQL query working.
Here is what happens inside SelectFields.php:
$relation = call_user_func([app($parentType->config['model']), $key]);
// Add the foreign key here, if it's a 'belongsTo'/'belongsToMany' relation
if(method_exists($relation, 'getForeignKey'))
{
$foreignKey = $relation->getForeignKey();
}
else if(method_exists($relation, 'getQualifiedForeignPivotKeyName'))
{
$foreignKey = $relation->getQualifiedForeignPivotKeyName();
// belongsToMany make PHP go there and $foreignKey is games.owner_id, cf getQualifiedForeignPivotKeyName() contents
}
else
{
$foreignKey = $relation->getQualifiedForeignKeyName();
}
$foreignKey = $parentTable ? ($parentTable . '.' . $foreignKey) : $foreignKey;
// Then it prepend again the table name: games.games.owner_idIt seems to me like it should prepent $parentTable only if not getting a qualified name.
Metadata
Metadata
Assignees
Labels
No labels