Using IS_IN_DB to do record lookup validation

[edit|delete]

Consider:

db.recipe.category.requires=IS_IN_DB(db,'category.id','category.name')

The parameters are:

  1. a set of records
  2. category.id describes how the field will be represented in the database
  3. category.name describes how the field will be represented to the user

For example you can do things like:

requires=IS_IN_DB(db(db.category.name.like('d%')),
                  'category.id',
                  'Name: %(name)s, id: %(id)s any text your like')


Comments


Fred on 2008-04-22 14:21:26 says
That works great. I'm using "%(last_name)s, %(first_names)s" for the third parameter when defining a foreign key to a table of people's names. [inappropriate?]

Post a comment