On Saturday, January 29, 2011 6:59:39 PM UTC-5, AW wrote:

> The following two lines of code are often used in the web2py book: 
>
> 1. db.define_table('person', Field('name', unique=True)) 
> 2. db.person.name.requires = IS_NOT_IN_DB(db, 'person.name') 
>
> Well, given that line 1 already avoids race condition at the database 
> level, isn't line 2 more or less redundant? Thanks in advance for your 
> opinion.

 
If I understand correctly, line 2 allows validation at the form level (i.e., 
before attempting to commit to the database), which enables more 
sophisticated handling of validation errors. For example, there is an error 
message (which can be customized) associated with failure of IS_NOT_IN_DB, 
which will be displayed to the user upon rejection of the form submittal. I 
don't think that would happen if you had only line 1 without line 2.
 
Anthony

Reply via email to