Thanks for the response Massimo! Let's say I have 2 fields (table.user_id and table.postal_code) in a many to many table. And this would be the controller level logic:
myduplicate = (db.table.user_id!= request.args[0]) & (table.postal_code!= request.args[1]).select().[0] So it's possible to have user A to have more than 1 postal code and same postal code have more than 1 user. So what I don't want is to duplicate an insert for the same thing (say user A with 01234 two times). User A cannot enter the same postal codes 2 times. How do I write this logic at the model level? On Aug 31, 7:59 pm, mdipierro <[email protected]> wrote: > Say you have two fields a and b and you want a+b to be unique. You > alwaysvalidateone at the time because only one can report an error. > Therefore you you want tovalidateb so that a+b is unique: > > db.table.b.requires=IS_NOT_IN_DB(db > (db.table.a==request.vars.a),'table.b') > > On Aug 31, 10:10 am, tititi <[email protected]> wrote: > > > > > Hi, > > > I'm looking at IS_IN_DB and IS_NOT_IN_DB to filter out inserts and > > want to know if it's possible to use 2 fields tovalidatean insert to > > prevent duplicates. For example, let's say I want emails to be unique > > in email field, now I want it to be email AND postalcode to be unique. > > I would like to use this at the model level and not a controller, is > > this possible? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

