Skip to content
Browse files

Rename Model.engine to active_relation_engine. Cache arel_table and t…

…he method takes no arguments now
  • Loading branch information...
1 parent 5971842 commit d2c4b3b672d52cddbc214e0fe5175cc92ca76f92 @lifo lifo committed Jan 2, 2010
Showing with 14 additions and 9 deletions.
  1. +13 −8 activerecord/lib/active_record/base.rb
  2. +1 −1 activerecord/lib/active_record/named_scope.rb
View
21 activerecord/lib/active_record/base.rb
@@ -1391,7 +1391,8 @@ def column_methods_hash #: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 @@ def merge_conditions(*conditions)
"(#{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 @@ def array_of_strings?(o)
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 @@ def expand_hash_conditions_for_aggregates(attrs)
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
View
2 activerecord/lib/active_record/named_scope.rb
@@ -27,7 +27,7 @@ def scoped(options = {}, &block)
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

0 comments on commit d2c4b3b

Please sign in to comment.
Something went wrong with that request. Please try again.