Updated validations

This commit is contained in:
Dominic Grimm 2022-01-15 19:06:13 +01:00
parent 8461f7dc16
commit 4f11106e74

View file

@ -11,21 +11,21 @@ module MW
column id : Int64, primary: true
column priority : Int32
validate :teacher, "must be present" do |teacher_vote|
!teacher_vote.teacher.nil?
validate :teacher, "must be vote unique" do |teacher_vote|
self.where(vote_id: teacher_vote.vote.id, teacher_id: teacher_vote.teacher.not_nil!.id).count.run.as(Int64).zero?
end
validate :teacher, "must be student unique" do |teacher_vote|
self.where(vote_id: teacher_vote.vote.id, teacher_id: teacher_vote.teacher.not_nil!.id).count == 0
end
validate :priority, "must be greater than 0" do |teacher_vote|
teacher_vote.priority > 0
validate :priority, "must be positive" do |teacher_vote|
teacher_vote.priority >= 0
end
validate :priority, "must be less than the number of teachers" do |teacher_vote|
teacher_vote.priority < Teacher.count
end
validate :priority, "must be vote unique" do |teacher_vote|
self.where(vote_id: teacher_vote.vote.id, priority: teacher_vote.priority).count.run.as(Int64).zero?
end
end
end
end