def get_attribute(name, parent = @join_dependency.join_base)
attribute = nil
if get_column(name, parent.active_record)
attribute = parent.table[name]
elsif (segments = name.to_s.split(/_/)).size > 1
remainder = []
found_assoc = nil
while remainder.unshift(segments.pop) && segments.size > 0 && !found_assoc do
if found_assoc = get_association(segments.join('_'), parent.active_record)
if found_assoc.options[:polymorphic]
unless delimiter = remainder.index('type')
raise PolymorphicAssociationMissingTypeError, "Polymorphic association specified without a type"
end
polymorphic_class, attribute_name = remainder[0...delimiter].join('_'),
remainder[delimiter + 1...remainder.size].join('_')
polymorphic_class = polymorphic_class.classify.constantize
join = build_or_find_association(found_assoc.name, parent, polymorphic_class)
attribute = get_attribute(attribute_name, join)
else
join = build_or_find_association(found_assoc.name, parent, found_assoc.klass)
attribute = get_attribute(remainder.join('_'), join)
end
end
end
end