[TYPO3-mvc] How to validate if input value is unique in table?

Manuel Simon typo3 at it11.info
Tue Feb 23 16:23:50 CET 2010


Hello Uwe,

I assume, your way of using a custom validator is right. In one of my
custom validators I've implemented a unique check like this:

I search my Repository for values with

$found = [...]->findByEmail($member->getEmail());
$count = count($found).

If $count is 0, everything is fine.
If $count is 1, you should check if $found[0]->getUid() is not equal to
$member->getUid().
If $count is greater than 1, you may have a problem ;-)

If you get one result from your repository and it's the same object as
the object to be updated - everything is fine. If not - add an error to
the validator and return false.

Kind regards,
Manuel

Am 22.02.2010 14:57, schrieb Uwe Michelfelder:
> Hi list,
> 
> I want to validate that the given email is not already used in the
> repository.
> 
> How is this solved correctly?
> 
> If I create a custom validator in the Domain Model checking against the
> repository by using ->findbyEmail() it would work for the add function,
> but not validate at updating the Object, because the repository finds
> the currently updated Object itself.
> 
> Any suggestions to solve this?
> 
> Greetings,
> Uwe



More information about the TYPO3-project-typo3v4mvc mailing list