Skip to content

Commit

Permalink
Allows us to properly scope for unique_within_region per #16739
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jan 3, 2018
1 parent cd17a20 commit 9863187
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/unique_within_region_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ def validate_each(record, attribute, value)
match_case = options.key?(:match_case) ? options[:match_case] : true
field_matches =
if match_case
record.class.where(attribute => value)
record.class.base_class.where(attribute => value)
else
record.class.where(record.class.arel_attribute(attribute).lower.eq(value.downcase))
record.class.base_class.where(record.class.base_class.arel_attribute(attribute).lower.eq(value.downcase))
end
unless field_matches.in_region(record.region_id).where.not(:id => record.id).empty?
record.errors.add(attribute, "is not unique within region #{record.region_id}")
Expand Down

0 comments on commit 9863187

Please sign in to comment.