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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -