0
这是我的模型文件。使用范围的日期时间字段的唯一性验证
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
我的主要目标是不允许在同一日期和child_id被保存在database.The验证我写的不是在这种情况下工作。
attendance_date是一个日期时间字段。
请帮我解决这个问题!
尝试'{范围:child_id}' –