and it really doesn’t work at all like I had hoped.
the docs says this should work
class TeacherSchedule < ActiveRecord::Base
validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
end
Just want to know if there are any experiences out there to share before I write my own validation code.
Greetings!I'm trying to set up a validation to ensure that a record is
unique across three columns; col_one, col_two, col_three. tried
this:validates_uniqueness_of :col_one, :scope=>[:col_two, :col_three]and it
really doesn't work at all like I had hoped.the docs says this should work
class TeacherSchedule < ActiveRecord::Base
validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
end
Just want to know if there are any experiences out there to share before I
write my own validation code.
Composite keys are frowned upon. You might want to reconsider what you are
attempting and introduce a few models to handle the relationship.
Of course, you could always create a customer validator. See the rails API.