validating uniqueness of has_many association with a string "checksum"
I had an idea to validate the uniqueness of a has_many association: what
if we generate a string based on the ids of the associated records?
For example:
class Exam
has_many :problems
validate :checksum, uniqueness: true #string
before_validate :check
def check
checksum = problems.map {|p| p.id}.join
end
end
(I'm not sure if "checksum" is the right term.)
Does anyone have thoughts on this approach? Is there a better way to
validate uniqueness of has_many?
No comments:
Post a Comment