Skip to content

Instantly share code, notes, and snippets.

@fkling
Created April 15, 2010 21:08
Show Gist options
  • Save fkling/367660 to your computer and use it in GitHub Desktop.
Save fkling/367660 to your computer and use it in GitHub Desktop.
<?php
class sfValidatorDoctrineUnique extends sfValidatorSchema {
//...
protected function doClean($values)
{
//...
$table = Doctrine::getTable($this->getOption('model'));
//...
$q = Doctrine_Query::create()
->from($this->getOption('model') . ' a');
foreach ($this->getOption('column') as $column)
{
$colName = $table->getColumnName($column);
//...
$q->addWhere('a.' . $colName . ' = ?', $values[$column]);
}
$object = $q->fetchOne();
// if no object or if we're updating the object, it's ok
if (!$object || $this->isUpdate($object, $values))
{
return $originalValues;
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment