Database update how to prevent duplicates

Hi

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.

validates_uniqueness_of would be the easiest way

http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001330

On 2/11/08, Thorsten M. [email protected] wrote:

validates_uniqueness_of would be the easiest way

ActiveRecord::Validations::ClassMethods

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


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/