1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactor bind_attribute to expand an association to actual attribute

This commit is contained in:
Ryuta Kamizono 2019-01-11 18:01:55 +09:00
parent eb5fef554f
commit 6c6c32463e
2 changed files with 5 additions and 5 deletions

View file

@ -44,6 +44,11 @@ module ActiveRecord
end
def bind_attribute(name, value) # :nodoc:
if reflection = klass._reflect_on_association(name)
name = reflection.foreign_key
value = value.read_attribute(reflection.klass.primary_key) unless value.nil?
end
attr = arel_attribute(name)
bind = predicate_builder.build_bind_attribute(attr.name, value)
yield attr, bind

View file

@ -56,11 +56,6 @@ module ActiveRecord
end
def build_relation(klass, attribute, value)
if reflection = klass._reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.klass.primary_key] unless value.nil?
end
relation = klass.unscoped
comparison = relation.bind_attribute(attribute, value) do |attr, bind|
return relation.none! unless bind.boundable?