How to check two fields for uniqueness

I need to check the uniqueness of two fields in an object (string) before adding them. Employee_id and area_id are two fields in my emp_area table. There may be several records with the same employee_id and several records with the same domain_id, but no two records can have the same employee_id and the same area_id. This is similar to the two fields making up a primary key or a unique key.

How can i do this.

thank

+72
ruby-on-rails
Oct 27 '09 at 19:56
source share
2 answers

how about this solution confirm combined values

validates :employee_id, uniqueness: { scope: :area_id } 
+96
Apr 14 '11 at 6:12
source share
 validates_uniqueness_of :employee_id, :scope => :area_id 
+69
Oct 27 '09 at 20:00
source share



All Articles