Permalink
Browse files

Refactor `bind_attribute` to expand an association to actual attribute

  • Loading branch information...
kamipo committed Jan 11, 2019
1 parent eb5fef5 commit 6c6c32463e71af4e3395a691052a89c4c1571acd
@@ -44,6 +44,11 @@ def arel_attribute(name) # :nodoc:
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
@@ -56,11 +56,6 @@ def find_finder_class_for(record)
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?

0 comments on commit 6c6c324

Please sign in to comment.