Saturday, March 26, 2011

Re: validate unique on batch imports

On Mar 26, 2011, at 18:40, euromark wrote:

> I encountered this problem several times with some batch imports or
> multiple form boxes saved together.
>
> You have a validation rule "isUnique" for the title.
> If you validate all your - lets say 15 - records, they are OK, even if
> two of them have the same name.
> Thats because the validation can only compare the 15 records to the
> current db content, not to each other.

If the title is supposed to be unique, put a UNIQUE index on the title column in the database. That will prevent duplicates from being inserted. Though it won't necessarily help you get a user-friendly error message, if that's what you're after.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: