Merge pull request #25665 from kamipo/remove_unused_table_arg

Remove unused `table` arg for `UniquenessValidator#scope_relation`
This commit is contained in:
Eileen M. Uchitelle 2016-08-05 16:41:45 -04:00 committed by GitHub
commit 53607c8e9f

@ -12,10 +12,9 @@ def initialize(options)
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
table = finder_class.arel_table
value = map_enum_attribute(finder_class, attribute, value)
relation = build_relation(finder_class, table, attribute, value)
relation = build_relation(finder_class, attribute, value)
if record.persisted?
if finder_class.primary_key
relation = relation.where.not(finder_class.primary_key => record.id_was || record.id)
@ -23,7 +22,7 @@ def validate_each(record, attribute, value)
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
end
end
relation = scope_relation(record, table, relation)
relation = scope_relation(record, relation)
relation = relation.merge(options[:conditions]) if options[:conditions]
if relation.exists?
@ -50,7 +49,7 @@ def find_finder_class_for(record) #:nodoc:
class_hierarchy.detect { |klass| !klass.abstract_class? }
end
def build_relation(klass, table, attribute, value) #:nodoc:
def build_relation(klass, attribute, value) # :nodoc:
if reflection = klass._reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.klass.primary_key] unless value.nil?
@ -63,6 +62,7 @@ def build_relation(klass, table, attribute, value) #:nodoc:
attribute_name = attribute.to_s
table = klass.arel_table
column = klass.columns_hash[attribute_name]
cast_type = klass.type_for_attribute(attribute_name)
@ -80,7 +80,7 @@ def build_relation(klass, table, attribute, value) #:nodoc:
end
end
def scope_relation(record, table, relation)
def scope_relation(record, relation)
Array(options[:scope]).each do |scope_item|
if reflection = record.class._reflect_on_association(scope_item)
scope_value = record.send(reflection.foreign_key)