/** * Check unique current map * @return bool */ protected function validationUnique($primaryKey) { $value = $this->getValue(); $field = $this->cursor; $map = clone $this->map; $options = ['limit' => 1]; if ($map instanceof SQLMapperOri) { $filter = ["{$field} = ?", $value]; } elseif ($map instanceof JigMapperOri) { $filter = [$field => $value]; } elseif ($map instanceof MongoMapperOri) { $filter = ["@{$field} = ?", $value]; } else { user_error('Invalid mapper instance'); } $map->load($filter, $options); $result = $map->dry(); if (!$result && $this->map->valid()) { $pa = []; $pb = []; $primaryKey = is_array($primaryKey) ? $primaryKey : [$primaryKey]; foreach ($primaryKey as $key) { $pa[$key] = $this->map->getPrevious($key); $pb[$key] = $map->get($key); } $result = $pa === $pb; } return (bool) $result; }