From 230904a1d4c9fef10f188d435329adddf244397a Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 30 Mar 2018 11:59:29 +0800 Subject: [PATCH] fixed updatemany deletemany --- src/Fasim/Core/Model.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Fasim/Core/Model.php b/src/Fasim/Core/Model.php index 3fb2f3a..39f0726 100644 --- a/src/Fasim/Core/Model.php +++ b/src/Fasim/Core/Model.php @@ -597,12 +597,25 @@ public static function db($m = null) { public static function updateMany($where, $updates) { $m = new static(); + $where = static::_convertValues($m, $where); + $updates = static::_convertValues($m, $updates); static::db()->update($m->getTableName(), $where, $updates); } public static function deleteMany($where) { $m = new static(); - static::db()->delete($m->getTableName(), $where); + static::db()->delete($m->getTableName(), static::_convertValues($m, $where)); + } + + private static function _convertValues($m, $where) { + if (is_array($where)) { + //值转换 + foreach ((array)$where as $k => $v) { + $m->$k = $v; + $where[$k] = $m->getOriginalValue($k); + } + } + return $where; }