From a07fb1509a0e72461126537a55429f0513f1e120 Mon Sep 17 00:00:00 2001 From: Paul Mejia Date: Mon, 27 Apr 2020 16:36:04 -0400 Subject: [PATCH] Get the related key field from the relationship instead of the metadata This allows us to get the relationship between entities with composed primary key --- src/Converter/RequestUriToSql.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Converter/RequestUriToSql.php b/src/Converter/RequestUriToSql.php index cdcc290..eeb3315 100755 --- a/src/Converter/RequestUriToSql.php +++ b/src/Converter/RequestUriToSql.php @@ -229,9 +229,13 @@ protected function prepareCustomSearch($hasSubquery = false): array $modelObject = new $model(); $model = $modelObject->getSource(); - $relatedKey = $metaData->getPrimaryKeyAttributes($modelObject)[0]; + $relationKey = $relatedKey = $metaData->getPrimaryKeyAttributes($modelObject)[0]; $relation = $this->model->getModelsManager()->getRelationsBetween(get_class($this->model), get_class($modelObject)); - $relationKey = (isset($relation) && count($relation)) ? $relation[0]->getFields() : $relatedKey; + + if (isset($relation) && count($relation)) { + $relatedKey = $relation[0]->getReferencedFields(); + $relationKey = $relation[0]->getFields(); + } $sql .= " INNER JOIN {$model} ON {$model}.{$relatedKey} = ("; $sql .= "SELECT {$model}.{$relatedKey} FROM {$model} WHERE {$model}.{$relatedKey} = {$classname}.{$relationKey}";