Skip to content

Commit

Permalink
correct bug where OR and AND were not being combined correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gte451f committed Nov 5, 2015
1 parent 0cebbf8 commit a9fff52
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/API/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ public function querySearcheHelper(\Phalcon\Mvc\Model\Query\BuilderInterface $qu
$query->andWhere("$fieldName $operator \"$newFieldValue\"");
break;

case 'or':
// make sure the field name is an array so we can use the same logic below for either circumstance
case 'or':
// format field name(s) is an array so we can use the same logic below for either circumstance
if (! is_array($processedSearchField['fieldName'])) {
$fieldNameArray = array(
$processedSearchField['fieldName']
Expand All @@ -436,7 +436,7 @@ public function querySearcheHelper(\Phalcon\Mvc\Model\Query\BuilderInterface $qu
$fieldNameArray = $processedSearchField['fieldName'];
}

// make sure the field value is an array so we can use the same logic below for either circumstance
// format field value(s) is an array so we can use the same logic below for either circumstance
if (! is_array($processedSearchField['fieldValue'])) {
$fieldValueArray = array(
$processedSearchField['fieldValue']
Expand All @@ -445,14 +445,17 @@ public function querySearcheHelper(\Phalcon\Mvc\Model\Query\BuilderInterface $qu
$fieldValueArray = $processedSearchField['fieldValue'];
}

$queryArr = [];
foreach ($fieldNameArray as $fieldName) {
$fieldName = $this->prependFieldNameNamespace($fieldName);
foreach ($fieldValueArray as $fieldValue) {
$operator = $this->determineWhereOperator($fieldValue);
$newFieldValue = $this->processFieldValue($fieldValue, $operator);
$query->orWhere("$fieldName $operator \"$newFieldValue\"");
$queryArr[] = "$fieldName $operator \"$newFieldValue\"";
}
}
$sql = implode(' OR ', $queryArr);
$query->andWhere($sql);
break;
}
}
Expand Down Expand Up @@ -483,8 +486,7 @@ private function processSearchFields($fieldParam)

/**
* This method determines whether the clause should be processed as an 'and' clause or an 'or' clause.
* This
* is determined based on the results from the \PhalconRest\API\Entity::processSearchFields() method. If that
* This is determined based on the results from the \PhalconRest\API\Entity::processSearchFields() method. If that
* method returns a string, we are dealing with an 'and' clause, if not, we are dealing with an 'or' clause.
*
* @param
Expand Down

0 comments on commit a9fff52

Please sign in to comment.