Skip to content

Commit

Permalink
Multiple JOIN
Browse files Browse the repository at this point in the history
  • Loading branch information
corentin committed Dec 14, 2017
1 parent 513b6c8 commit 930d833
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Command/PopulateElasticCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 930d833

Please sign in to comment.