Skip to content

Commit

Permalink
Fix #8366 - V8 API Filtering W/ OR Operator Chained Conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
serfreeman1337 authored and mattlorimer committed Mar 1, 2022
1 parent e88f094 commit e9414a1
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Api/V8/JsonApi/Repository/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public function parseWhere(\SugarBean $bean, array $params)
unset($params['operator']);
}

$params = $this->addDeletedParameter($params);
$deleted = false;
if (isset($params['deleted'])) {
if (isset($params['deleted']['eq'])) {
$deleted = ($params['deleted']['eq'] == 1);
}

unset($params['deleted']);
}

$where = [];
foreach ($params as $field => $expr) {
Expand Down Expand Up @@ -75,12 +82,25 @@ public function parseWhere(\SugarBean $bean, array $params)
}
}

return implode(sprintf(' %s ', $operator), $where);
if (empty($where)) {
return sprintf(
"%s.deleted = '%d'",
$bean->getTableName(),
$deleted
);
}

return sprintf(
"(%s) AND %s.deleted = '%d'",
implode(sprintf(' %s ', $operator), $where),
$bean->getTableName(),
$deleted
);
}

/**
* Only return deleted records if they were explicitly requested
*
* @deprecated
* @param array $params
* @return array
*/
Expand Down

0 comments on commit e9414a1

Please sign in to comment.