There are many options. Do you prefer to use two separate reference fields
or a single list:reference field? What should happen when a duplicate
insert is attempted: (a) fail silently, (b) return an error message, (c)
throw an exception, (d) do an update on the existing record?
Note, unique=True won't work if using two separate fields, though you could
instead set a multi-column unique constraint in the database (the DAL
cannot do that, so you'll have to do it externally).
If you want to use the IS_NOT_IN_DB validator (in conjunction with
.validate_and_insert), you could do:
Field('second_reference', 'reference other_table',
requires=IS_NOT_IN_DB(db(db.this_table.first_reference ==
first_id), 'this_table.second_reference'))
So, you only create an IS_NOT_IN_DB validator for the second field, setting
to prevent duplicates on second_reference only among the set of records
where first_reference also matches.
Anthony
On Friday, January 22, 2016 at 5:38:27 AM UTC-5, Pierre wrote:
>
> What is unclear is at what level uniqueness should be enforced ?
> database, form, web2py commands ?
>
> unique=True is at database level but it throws a ticket (in case web2py
> attempts to duplicate a record) so I suppose this is not wanted once the
> app is deployed
> Is it good/efficient to use validate_and_insert or update_or_insert
> to check uniqueness at web2py level and can these commands be combined with
> unique=True (prevent ticketing) ?
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.