Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SonataAdminBundle: Validate Unique
class ModelAdmin extend Admin
// ...
public function validate(ErrorElement $errorElement, $object)
// find object with the same uniqueField-value
$other = $this->modelManager->findOneBy($this->getClass(), array('uniqueField' => $object->getUniqueSlug()));
if (null !== $other && !$other->equals($object)) {
->addViolation('The unique field must be unique!')

This comment has been minimized.

Copy link

joffreycarle commented Jan 27, 2014

It should works better with an 's'.

class ModelAdmin extends Admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.