How do I validate two fields for uniqueness

前端 未结 2 925
忘了有多久
忘了有多久 2021-01-30 19:21

I need to validate the uniqueness of two fields in an object (row) before I add them. Employee_id and area_id are the two fields in my emp_area table. There can be multiple re

相关标签:
2条回答
  • 2021-01-30 20:01
    validates_uniqueness_of :employee_id, :scope => :area_id
    
    0 讨论(0)
  • 2021-01-30 20:23

    what about this solution Validate combined values

    validates :employee_id, uniqueness: { scope: :area_id }
    
    0 讨论(0)
提交回复
热议问题