database update how to prevent duplicates


database schema has items

login groupid

Now when database is updated how can I check if there is entry already with same information example:

new item is created with values login=doe groupid=10 and if such item exists already on database then error is returned ?

I believe on model you can do something like this, correct ?

I know on model you can check if login=doe is already there but I need to make sure that if both conditions apply at the same time.

Note the commentary about creating a unique index if you want this to be safe in the face of concurrency.