instance method
validate_each
Ruby on Rails 3.1.12
Since v3.0.20 Last seen in v3.2.22.5Signature
validate_each(record, attribute, value)
No documentation comment.
Parameters
-
recordreq -
attributereq -
valuereq
Source
# File activerecord/lib/active_record/validations/uniqueness.rb, line 15
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
table = finder_class.arel_table
coder = record.class.serialized_attributes[attribute.to_s]
if value && coder
value = coder.dump value
end
relation = build_relation(finder_class, table, attribute, value)
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
Array.wrap(options[:scope]).each do |scope_item|
scope_value = record.send(scope_item)
relation = relation.and(table[scope_item].eq(scope_value))
end
if finder_class.unscoped.where(relation).exists?
record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
end
end
Defined in activerecord/lib/active_record/validations/uniqueness.rb line 15
· View on GitHub
· Improve this page
· Find usages on GitHub