1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make type_condition return Arel predicate and not a string condition

This commit is contained in:
Pratik Naik 2010-01-16 04:17:23 +05:30
parent 99dd107760
commit 2d0bc08a7e
2 changed files with 4 additions and 6 deletions

View file

@ -144,7 +144,7 @@ module ActiveRecord
end end
def build_sti_condition def build_sti_condition
@reflection.through_reflection.klass.send(:type_condition) @reflection.through_reflection.klass.send(:type_condition).to_sql
end end
alias_method :sql_conditions, :conditions alias_method :sql_conditions, :conditions

View file

@ -1622,14 +1622,12 @@ module ActiveRecord #:nodoc:
o.is_a?(Array) && o.all?{|obj| obj.is_a?(String)} o.is_a?(Array) && o.all?{|obj| obj.is_a?(String)}
end end
def type_condition(table_alias = nil) def type_condition
table = Arel::Table.new(table_name, :engine => active_relation_engine, :as => table_alias) sti_column = active_relation_table[inheritance_column]
sti_column = table[inheritance_column]
condition = sti_column.eq(sti_name) condition = sti_column.eq(sti_name)
subclasses.each{|subclass| condition = condition.or(sti_column.eq(subclass.sti_name)) } subclasses.each{|subclass| condition = condition.or(sti_column.eq(subclass.sti_name)) }
condition.to_sql condition
end end
# Guesses the table name, but does not decorate it with prefix and suffix information. # Guesses the table name, but does not decorate it with prefix and suffix information.