Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use arel for building the STI type condition

  • Loading branch information...
commit d200d080041bc4cefba8a8d39943b233ee2630a0 1 parent 7789663
@lifo lifo authored
Showing with 7 additions and 7 deletions.
  1. +7 −7 activerecord/lib/active_record/base.rb
View
14 activerecord/lib/active_record/base.rb
@@ -1681,14 +1681,14 @@ def array_of_strings?(o)
o.is_a?(Array) && o.all?{|obj| obj.is_a?(String)}
end
- def type_condition(table_alias=nil)
- quoted_table_alias = self.connection.quote_table_name(table_alias || table_name)
- quoted_inheritance_column = connection.quote_column_name(inheritance_column)
- type_condition = subclasses.inject("#{quoted_table_alias}.#{quoted_inheritance_column} = '#{sti_name}' " ) do |condition, subclass|
- condition << "OR #{quoted_table_alias}.#{quoted_inheritance_column} = '#{subclass.sti_name}' "
- end
+ def type_condition(table_alias = nil)
+ table = Arel::Table.new(table_name, :engine => engine, :as => table_alias)
+
+ sti_column = table[inheritance_column]
+ condition = sti_column.eq(sti_name)
+ subclasses.each{|subclass| condition = condition.or(sti_column.eq(subclass.sti_name)) }
- " (#{type_condition}) "
+ condition.to_sql
end
# Guesses the table name, but does not decorate it with prefix and suffix information.
Please sign in to comment.
Something went wrong with that request. Please try again.