From 930d83391ab86b3bb679ee8c195a885ef385382b Mon Sep 17 00:00:00 2001 From: corentin Date: Thu, 14 Dec 2017 17:47:05 +0100 Subject: [PATCH] Multiple JOIN --- Command/PopulateElasticCommand.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Command/PopulateElasticCommand.php b/Command/PopulateElasticCommand.php index 85e0c15..fe7cd13 100644 --- a/Command/PopulateElasticCommand.php +++ b/Command/PopulateElasticCommand.php @@ -309,25 +309,31 @@ private function _resetType($type) */ private function _getQuery($type, &$iResults) { - $id = filter_var($this->id, FILTER_SANITIZE_NUMBER_INT); + $id = filter_var($this->id, FILTER_SANITIZE_STRING); $where = filter_var($this->where, FILTER_SANITIZE_STRING); - $join = filter_var($this->join, FILTER_SANITIZE_STRING); + $joins = filter_var($this->join, FILTER_SANITIZE_STRING); $entity = 'u'; # Forge clause JOIN $clauseJoin = ''; - if ($join) { - $clauseJoin = $join ? " LEFT JOIN u.{$join} v " : ''; - $entity = 'v'; + $aJoins = explode(',', $joins); + foreach ($aJoins as $join) { + if (empty($join)) { + break; + } + $newId = ($newId ?? 0) + 1; + $newEntity = "u_$newId"; + $clauseJoin .= " LEFT JOIN {$entity}.{$join} {$newEntity} "; + $entity = $newEntity; } # Forge clause WHERE $clauseWhere = ''; if ($id && $where) { - $clauseWhere = " WHERE {$entity}.{$where} = {$id}"; + $clauseWhere = " WHERE {$entity}.{$where} = '{$id}'"; } if ($id && !$where) { - $clauseWhere = " WHERE {$entity}.id = {$id}"; + $clauseWhere = " WHERE {$entity}.id = '{$id}'"; } # COUNT results