From b35873a575586d31e9de681aec31d4b884b25aba Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 2 Jan 2010 00:25:29 +0530 Subject: [PATCH] Rename Model.arel_table to Model.active_relation --- .../lib/active_record/associations.rb | 4 +-- activerecord/lib/active_record/base.rb | 26 +++++++++---------- .../lib/active_record/calculations.rb | 4 +-- .../lib/active_record/locking/optimistic.rb | 8 +++--- activerecord/lib/active_record/named_scope.rb | 2 +- .../relation/calculation_methods.rb | 4 +-- .../relation/predicate_builder.rb | 10 +++---- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index dc1fa08941..80e6acf34c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1706,7 +1706,7 @@ module ActiveRecord def construct_finder_arel_with_included_associations(options, join_dependency) scope = scope(:find) - relation = arel_table + relation = active_relation for association in join_dependency.join_associations relation = association.join_relation(relation) @@ -1751,7 +1751,7 @@ module ActiveRecord def construct_finder_sql_for_association_limiting(options, join_dependency) scope = scope(:find) - relation = arel_table + relation = active_relation for association in join_dependency.join_associations relation = association.join_relation(relation) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d12397d5c0..7cefba2b82 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -816,7 +816,7 @@ module ActiveRecord #:nodoc: # # Delete multiple rows # Todo.delete([2,3,4]) def delete(id_or_array) - arel_table.where(construct_conditions(nil, scope(:find))).delete(id_or_array) + active_relation.where(construct_conditions(nil, scope(:find))).delete(id_or_array) end # Destroy an object (or multiple objects) that has the given id, the object is instantiated first, @@ -873,7 +873,7 @@ module ActiveRecord #:nodoc: def update_all(updates, conditions = nil, options = {}) scope = scope(:find) - relation = arel_table + relation = active_relation if conditions = construct_conditions(conditions, scope) relation = relation.where(Arel::SqlLiteral.new(conditions)) @@ -938,7 +938,7 @@ module ActiveRecord #:nodoc: # Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent # associations or call your before_* or +after_destroy+ callbacks, use the +destroy_all+ method instead. def delete_all(conditions = nil) - arel_table.where(construct_conditions(conditions, scope(:find))).delete_all + active_relation.where(construct_conditions(conditions, scope(:find))).delete_all end # Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. @@ -1392,7 +1392,7 @@ module ActiveRecord #:nodoc: def reset_column_information undefine_attribute_methods @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil - @arel_table = @active_relation_engine = nil + @active_relation = @active_relation_engine = nil end def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc: @@ -1505,8 +1505,8 @@ module ActiveRecord #:nodoc: "(#{segments.join(') AND (')})" unless segments.empty? end - def arel_table - @arel_table ||= Relation.new(self, active_relation_table) + def active_relation + @active_relation ||= Relation.new(self, active_relation_table) end def active_relation_table(table_name_alias = nil) @@ -1570,7 +1570,7 @@ module ActiveRecord #:nodoc: def construct_finder_arel(options = {}, scope = scope(:find)) validate_find_options(options) - relation = arel_table. + relation = active_relation. joins(construct_join(options[:joins], scope)). where(construct_conditions(options[:conditions], scope)). select(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))). @@ -1671,7 +1671,7 @@ module ActiveRecord #:nodoc: def build_association_joins(joins) join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, joins, nil) - relation = arel_table.relation + relation = active_relation.relation join_dependency.join_associations.map { |association| if (association_relation = association.relation).is_a?(Array) [Arel::InnerJoin.new(relation, association_relation.first, association.association_join.first).joins(relation), @@ -2314,7 +2314,7 @@ module ActiveRecord #:nodoc: # be made (since they can't be persisted). def destroy unless new_record? - self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all + self.class.active_relation.where(self.class.active_relation[self.class.primary_key].eq(id)).delete_all end @destroyed = true @@ -2601,7 +2601,7 @@ module ActiveRecord #:nodoc: def update(attribute_names = @attributes.keys) attributes_with_values = arel_attributes_values(false, false, attribute_names) return 0 if attributes_with_values.empty? - self.class.arel_table.where(self.class.arel_table[self.class.primary_key].eq(id)).update(attributes_with_values) + self.class.active_relation.where(self.class.active_relation[self.class.primary_key].eq(id)).update(attributes_with_values) end # Creates a record with values matching those of the instance attributes @@ -2614,9 +2614,9 @@ module ActiveRecord #:nodoc: attributes_values = arel_attributes_values new_id = if attributes_values.empty? - self.class.arel_table.insert connection.empty_insert_statement_value + self.class.active_relation.insert connection.empty_insert_statement_value else - self.class.arel_table.insert attributes_values + self.class.active_relation.insert attributes_values end self.id ||= new_id @@ -2711,7 +2711,7 @@ module ActiveRecord #:nodoc: if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array)) value = value.to_yaml end - attrs[self.class.arel_table[name]] = value + attrs[self.class.active_relation[name]] = value end end end diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index d51d9f2159..20d287faeb 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -162,7 +162,7 @@ module ActiveRecord join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(options[:joins], scope)) construct_calculation_arel_with_included_associations(options, join_dependency) else - arel_table. + active_relation. joins(construct_join(options[:joins], scope)). from((scope && scope[:from]) || options[:from]). where(construct_conditions(options[:conditions], scope)). @@ -178,7 +178,7 @@ module ActiveRecord def construct_calculation_arel_with_included_associations(options, join_dependency) scope = scope(:find) - relation = arel_table + relation = active_relation for association in join_dependency.join_associations relation = association.join_relation(relation) diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index 7911370332..f9e538c586 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -78,11 +78,11 @@ module ActiveRecord attribute_names.uniq! begin - arel_table = self.class.arel_table + relation = self.class.active_relation - affected_rows = arel_table.where( - arel_table[self.class.primary_key].eq(quoted_id).and( - arel_table[self.class.locking_column].eq(quote_value(previous_value)) + affected_rows = relation.where( + relation[self.class.primary_key].eq(quoted_id).and( + relation[self.class.locking_column].eq(quote_value(previous_value)) ) ).update(arel_attributes_values(false, false, attribute_names)) diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 02ee2d1401..5959265d5e 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.spawn + finder_needs_type_condition? ? active_relation.where(type_condition) : active_relation.spawn else construct_finder_arel_with_includes end diff --git a/activerecord/lib/active_record/relation/calculation_methods.rb b/activerecord/lib/active_record/relation/calculation_methods.rb index a925a99464..5246c7bc5d 100644 --- a/activerecord/lib/active_record/relation/calculation_methods.rb +++ b/activerecord/lib/active_record/relation/calculation_methods.rb @@ -53,7 +53,7 @@ module ActiveRecord def execute_simple_calculation(operation, column_name, distinct) #:nodoc: column = if @klass.column_names.include?(column_name.to_s) - Arel::Attribute.new(@klass.arel_table, column_name) + Arel::Attribute.new(@klass.active_relation, column_name) else Arel::SqlLiteral.new(column_name == :all ? "*" : column_name.to_s) end @@ -77,7 +77,7 @@ module ActiveRecord select_statement = if operation == 'count' && column_name == :all "COUNT(*) AS count_all" else - Arel::Attribute.new(@klass.arel_table, column_name).send(operation).as(aggregate_alias).to_sql + Arel::Attribute.new(@klass.active_relation, column_name).send(operation).as(aggregate_alias).to_sql end select_statement << ", #{group_field} AS #{group_alias}" diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index d5e0c90184..6b7d941350 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -7,20 +7,20 @@ module ActiveRecord def build_from_hash(attributes, default_table) predicates = attributes.map do |column, value| - arel_table = default_table + table = default_table if value.is_a?(Hash) - arel_table = Arel::Table.new(column, @engine) - build_from_hash(value, arel_table) + table = Arel::Table.new(column, :engine => @engine) + build_from_hash(value, table) else column = column.to_s if column.include?('.') table_name, column = column.split('.', 2) - arel_table = Arel::Table.new(table_name, @engine) + table = Arel::Table.new(table_name, :engine => @engine) end - attribute = arel_table[column] || Arel::Attribute.new(arel_table, column.to_sym) + attribute = table[column] || Arel::Attribute.new(table, column.to_sym) case value when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope