ruby - Uniqueness validation on datetime field with scope -


this model file.

class attendance < activerecord::base belongs_to :staff, class_name: 'user', foreign_key: 'staff_id', inverse_of: :attendances belongs_to :child, inverse_of: :attendances  validates :attendance_date, uniqueness: {scope: :child}   end 

my main goal not allow same date , child_id saved in database.the validation wrote not working in scenario.

the attendance_date datetime field.

please me solve issue!!

validate uniqueness scope add multiple column constraint uniqueness. can add column's want use applying uniqueness:

try this:

validates :attendance_date, uniqueness: {scope: :child_id}  

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -