diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-01 23:15:48 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-01 23:15:48 +0530 |
commit | d200d080041bc4cefba8a8d39943b233ee2630a0 (patch) | |
tree | 960c923b0c056923f33a6c7416153c5d13606263 /activerecord | |
parent | 7789663a7d8647f5a20c585dc177cbd18aace1c3 (diff) | |
download | rails-d200d080041bc4cefba8a8d39943b233ee2630a0.tar.gz rails-d200d080041bc4cefba8a8d39943b233ee2630a0.tar.bz2 rails-d200d080041bc4cefba8a8d39943b233ee2630a0.zip |
Use arel for building the STI type condition
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index fb160dea9a..36b46eee5e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1681,14 +1681,14 @@ module ActiveRecord #:nodoc: 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. |