diff options
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 21 | ||||
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 2 |
2 files changed, 14 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 36b46eee5e..d12397d5c0 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1391,7 +1391,8 @@ module ActiveRecord #:nodoc: # end def reset_column_information undefine_attribute_methods - @arel_table = @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil + @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil + @arel_table = @active_relation_engine = nil end def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc: @@ -1504,12 +1505,16 @@ module ActiveRecord #:nodoc: "(#{segments.join(') AND (')})" unless segments.empty? end - def arel_table(table = nil) - Relation.new(self, Arel::Table.new(table || table_name)) + def arel_table + @arel_table ||= Relation.new(self, active_relation_table) end - def engine - @engine ||= Arel::Sql::Engine.new(self) + def active_relation_table(table_name_alias = nil) + Arel::Table.new(table_name, :as => table_name_alias) + end + + def active_relation_engine + @active_relation_engine ||= Arel::Sql::Engine.new(self) end private @@ -1682,7 +1687,7 @@ module ActiveRecord #:nodoc: end def type_condition(table_alias = nil) - table = Arel::Table.new(table_name, :engine => engine, :as => table_alias) + table = Arel::Table.new(table_name, :engine => active_relation_engine, :as => table_alias) sti_column = table[inheritance_column] condition = sti_column.eq(sti_name) @@ -2042,8 +2047,8 @@ module ActiveRecord #:nodoc: def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name) attrs = expand_hash_conditions_for_aggregates(attrs) - table = Arel::Table.new(default_table_name, engine) - builder = PredicateBuilder.new(engine) + table = Arel::Table.new(default_table_name, active_relation_engine) + builder = PredicateBuilder.new(active_relation_engine) builder.build_from_hash(attrs, table).map(&:to_sql).join(' AND ') end alias_method :sanitize_sql_hash, :sanitize_sql_hash_for_conditions diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index a6336e762a..02ee2d1401 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -27,7 +27,7 @@ module ActiveRecord Scope.new(self, options, &block) else unless scoped?(:find) - finder_needs_type_condition? ? arel_table.where(type_condition) : arel_table + finder_needs_type_condition? ? arel_table.where(type_condition) : arel_table.spawn else construct_finder_arel_with_includes end |