rgmrtn
rgmrtn

Reputation: 155

Google App Maker: Prevent Duplicate Entries

How do I prevent the user from adding a duplicate entry in a specific field. I have a database in which I want a field to contain unique identifying names for equipment, how do I ensure a user can't add equipment to the database with the same identifier.

Upvotes: 1

Views: 672

Answers (1)

Vasyl Petrushko
Vasyl Petrushko

Reputation: 366

You can add onSave and onCreate Event handlers (Model -> Events) which will check if identifier is in use:

var query = app.models.Hardware.newQuery();
query.filters.HardwareId._equals = record.HardwareId;
if (query.run().length) {
  throw 'Hardware ID "' + record.HardwareId + '" is in use.';
}

Also in CloudSQL you can define unique index on the field.

Upvotes: 2

Related Questions