From 26c8e1fedf1ea45ff0c8ceb6e4856f060d206ed6 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 3 Mar 2022 20:59:46 +0000 Subject: [PATCH] Allow API4 match to match an empty value --- Civi/Api4/Generic/AbstractSaveAction.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Civi/Api4/Generic/AbstractSaveAction.php b/Civi/Api4/Generic/AbstractSaveAction.php index 50aa311c46..94b932efd3 100644 --- a/Civi/Api4/Generic/AbstractSaveAction.php +++ b/Civi/Api4/Generic/AbstractSaveAction.php @@ -142,7 +142,13 @@ abstract class AbstractSaveAction extends AbstractAction { $where = []; foreach ($record as $key => $val) { if (isset($val) && in_array($key, $this->match, TRUE)) { - $where[] = [$key, '=', $val]; + if ($val === '' || is_null($val)) { + // If we want to match empty string we have to match on NULL/'' + $where[] = [$key, 'IS EMPTY']; + } + else { + $where[] = [$key, '=', $val]; + } } } if (count($where) === count($this->match)) { -- 2.25.1