From 65f7ae77c9b4364ba22a94c322555b33b6a16222 Mon Sep 17 00:00:00 2001 From: Jon Langevin Date: Mon, 26 Mar 2012 03:53:55 -0300 Subject: [PATCH] Updating unique validator to ignore matches with same pk. --- extra/EMongoUniqueValidator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extra/EMongoUniqueValidator.php b/extra/EMongoUniqueValidator.php index f264846c..85a27e7b 100644 --- a/extra/EMongoUniqueValidator.php +++ b/extra/EMongoUniqueValidator.php @@ -28,7 +28,9 @@ public function validateAttribute($object, $attribute) return; $criteria = new EMongoCriteria; - $criteria->{$attribute} = $value; + if(!$object->getIsNewRecord()) + $criteria->addCond('_id', '!=', $object->getPrimaryKey()); + $criteria->addCond($attribute, '==', $value); $count = $object->model()->count($criteria); if($count !== 0)