Skip to content

Commit

Permalink
Merge pull request #39 from bakaphp/fix-relationship-search
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken authored Apr 28, 2020
2 parents 4469c4a + a07fb15 commit abf52b2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Converter/RequestUriToSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down

0 comments on commit abf52b2

Please sign in to comment.