DEV: allow to have duplicate topic titles if categegory is different (#10034)

Co-authored-by: Robin Ward <robin.ward@gmail.com>

Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
Bernhard Suttner
2020-06-18 17:19:47 +02:00
committed by GitHub
parent ec794c7f29
commit e31471585a
6 changed files with 38 additions and 6 deletions

View File

@ -12,7 +12,7 @@ class UniqueAmongValidator < ActiveRecord::Validations::UniquenessValidator
# do nothing further unless there were some duplicates.
unless new_errors == 0
# now look only in the collection we care about.
dupes = options[:collection].call.where("lower(#{attribute}) = ?", value.downcase)
dupes = options[:collection].call(record).where("lower(#{attribute}) = ?", value.downcase)
dupes = dupes.where("id != ?", record.id) if record.persisted?
# pop off the error, if it was a false positive