Updated validations
This commit is contained in:
parent
8461f7dc16
commit
4f11106e74
1 changed files with 8 additions and 8 deletions
|
@ -11,21 +11,21 @@ module MW
|
||||||
column id : Int64, primary: true
|
column id : Int64, primary: true
|
||||||
column priority : Int32
|
column priority : Int32
|
||||||
|
|
||||||
validate :teacher, "must be present" do |teacher_vote|
|
validate :teacher, "must be vote unique" do |teacher_vote|
|
||||||
!teacher_vote.teacher.nil?
|
self.where(vote_id: teacher_vote.vote.id, teacher_id: teacher_vote.teacher.not_nil!.id).count.run.as(Int64).zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
validate :teacher, "must be student unique" do |teacher_vote|
|
validate :priority, "must be positive" do |teacher_vote|
|
||||||
self.where(vote_id: teacher_vote.vote.id, teacher_id: teacher_vote.teacher.not_nil!.id).count == 0
|
teacher_vote.priority >= 0
|
||||||
end
|
|
||||||
|
|
||||||
validate :priority, "must be greater than 0" do |teacher_vote|
|
|
||||||
teacher_vote.priority > 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
validate :priority, "must be less than the number of teachers" do |teacher_vote|
|
validate :priority, "must be less than the number of teachers" do |teacher_vote|
|
||||||
teacher_vote.priority < Teacher.count
|
teacher_vote.priority < Teacher.count
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue