Permalink
Browse files

Merge pull request #25665 from kamipo/remove_unused_table_arg

Remove unused `table` arg for `UniquenessValidator#scope_relation`
  • Loading branch information...
eileencodes committed Aug 5, 2016
2 parents 2bd9ec6 + f3cb1f8 commit 53607c8e9fd74e0bc3925e940583d97429e88266
Showing with 5 additions and 5 deletions.
  1. +5 −5 activerecord/lib/active_record/validations/uniqueness.rb
@@ -12,18 +12,17 @@ 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)
else
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)

0 comments on commit 53607c8

Please sign in to comment.