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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -