Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Updating unique validator to ignore matches with same pk. #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion extra/EMongoUniqueValidator.php
Expand Up @@ -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)
Expand Down