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:
parent
eb5fef554f
commit
6c6c32463e
2 changed files with 5 additions and 5 deletions
|
@ -44,6 +44,11 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def bind_attribute(name, value) # :nodoc:
|
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)
|
attr = arel_attribute(name)
|
||||||
bind = predicate_builder.build_bind_attribute(attr.name, value)
|
bind = predicate_builder.build_bind_attribute(attr.name, value)
|
||||||
yield attr, bind
|
yield attr, bind
|
||||||
|
|
|
@ -56,11 +56,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_relation(klass, attribute, value)
|
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
|
relation = klass.unscoped
|
||||||
comparison = relation.bind_attribute(attribute, value) do |attr, bind|
|
comparison = relation.bind_attribute(attribute, value) do |attr, bind|
|
||||||
return relation.none! unless bind.boundable?
|
return relation.none! unless bind.boundable?
|
||||||
|
|
Loading…
Reference in a new issue