On Jan 31, 2011, at 7:53 AM, AW wrote:
> 
> Anthony, that's quite helpful advice.
> 
> I'd suspected that has something to do with different errors and
> couldn't go as far as you showed in your post. Thanks.

Note that, besides unique, there are two other conditions that are enforced at 
the database (SQL) level: notnull and ondelete. There's a brief discussion of 
this in the web2py book's DAL chapter.


> 
> 
> 
> 
> On Jan 29, 7:33 pm, Anthony <abasta...@gmail.com> wrote:
>> 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