I, too, am wondering why this should be so. I just ran into this issue with an api that I'm developing. The api needs to do an insert of a field called 'name' that requires=[IS_NOT_EMPTY(),IS_IN_DB(...)]. It seems redundant that I should have to do this an error check that the name argument is not "" from within my api prior to doing an insert, when this is already specified in the db.define_table section. What is the logic behind the reason for this behavior?
On Jul 18, 7:57 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > It is probably useful to repeat this from the book, for the community: > > When you think of dataflow, from your client to your persistent store: > > ".requires=..." is enforced at the level of forms; > > "required=True" is enforced by the DAL (prior to insert); > > "notnull", "unique", and "ondelete" is enforced at the db server. > > On Sat, Jul 18, 2009 at 6:47 PM, ionel <ionelanton...@gmail.com> wrote: > > > Thanks. It make sense. > > > On Jul 18, 3:16 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > > > On Sat, Jul 18, 2009 at 1:00 PM, ionel <ionelanton...@gmail.com> wrote: > > > > > Hello, > > > > I have the following situation: > > > > > Model: > > > > > db.define_table('country', db.Field('country', 'string', length=50)) > > > > > db.define_table(region', > > > > db.Field('name', 'string', length=50), > > > > db.Field('country', 'reference country') > > > > ) > > > > db.region.country.requires=IS_IN_DB(db, 'country.id', '%(country)s', > > > > orderby=db.country.country) > > > > > Controller: > > > > > def test(): > > > > country_id = db.country.insert(country=-1, region="Same > > > > region") > > > > > Problem: > > > > > There is no country.id = -1 in the country table, but INSERT is > > > > executed despite the validator > > > > db.region.country.requires is a validator; it is not a constraint on DAL; > > it > > > is on SQLForm; > > > > > db.region.country.requires=IS_IN_DB(db, 'country.id', '%(country)s', > > > > orderby=db.country.country) > > > > > Is this an expected behavior? > > > > > Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---