Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Split arel_table into method to get a relation and another to…

… memoize the default relation."

This reverts commit bd51790.
  • Loading branch information...
commit 7b3d85db4c58e2f719981efd6ef5a6b870f6ab49 1 parent 3f54f31
@jeremy jeremy authored
View
4 activerecord/lib/active_record/associations.rb
@@ -1698,7 +1698,7 @@ def select_all_rows(options, join_dependency)
def construct_finder_arel_with_included_associations(options, join_dependency)
scope = scope(:find)
- relation = arel_table_for((scope && scope[:from]) || options[:from])
+ relation = arel_table((scope && scope[:from]) || options[:from])
for association in join_dependency.join_associations
relation = association.join_relation(relation)
@@ -1741,7 +1741,7 @@ def select_limited_ids_array(options, join_dependency)
def construct_finder_sql_for_association_limiting(options, join_dependency)
scope = scope(:find)
- relation = arel_table_for(options[:from])
+ relation = arel_table(options[:from])
for association in join_dependency.join_associations
relation = association.join_relation(relation)
View
4 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -56,7 +56,7 @@ def insert_record(record, force = true, validate = true)
if @reflection.options[:insert_sql]
@owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
else
- relation = arel_table_for(@reflection.options[:join_table])
+ relation = arel_table(@reflection.options[:join_table])
attributes = columns.inject({}) do |attrs, column|
case column.name.to_s
when @reflection.primary_key_name.to_s
@@ -82,7 +82,7 @@ def delete_records(records)
if sql = @reflection.options[:delete_sql]
records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
else
- relation = arel_table_for(@reflection.options[:join_table])
+ relation = arel_table(@reflection.options[:join_table])
relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id).
and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id)))
).delete
View
2  activerecord/lib/active_record/associations/has_many_association.rb
@@ -69,7 +69,7 @@ def delete_records(records)
when :delete_all
@reflection.klass.delete(records.map { |record| record.id })
else
- relation = arel_table_for(@reflection.table_name)
+ relation = arel_table(@reflection.table_name)
relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id).
and(Arel::Predicates::In.new(relation[@reflection.klass.primary_key], records.map(&:id)))
).update(relation[@reflection.primary_key_name] => nil)
View
12 activerecord/lib/active_record/base.rb
@@ -1493,11 +1493,11 @@ def merge_conditions(*conditions)
def arel_table(table = nil)
- @arel_table ||= arel_table_for(table_name)
- end
-
- def arel_table_for(table_name)
- Relation.new(self, Arel::Table.new(table_name))
+ table = table_name if table.blank?
+ if @arel_table.nil? || @arel_table.name != table
+ @arel_table = Relation.new(self, Arel::Table.new(table))
+ end
+ @arel_table
end
private
@@ -1666,7 +1666,7 @@ def default_select(qualified)
def construct_finder_arel(options = {}, scope = scope(:find))
# TODO add lock to Arel
- relation = arel_table_for(options[:from]).
+ relation = arel_table(options[:from]).
joins(construct_join(options[:joins], scope)).
conditions(construct_conditions(options[:conditions], scope)).
select(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))).
View
4 activerecord/lib/active_record/calculations.rb
@@ -146,7 +146,7 @@ def calculate(operation, column_name, options = {})
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, construct_join(options[:joins], scope))
construct_finder_arel_with_included_associations(options, join_dependency)
else
- relation = arel_table_for(options[:from]).
+ relation = arel_table(options[:from]).
joins(construct_join(options[:joins], scope)).
conditions(construct_conditions(options[:conditions], scope)).
order(options[:order]).
@@ -164,7 +164,7 @@ def calculate(operation, column_name, options = {})
def execute_simple_calculation(operation, column_name, options, relation) #:nodoc:
column = if column_names.include?(column_name.to_s)
- Arel::Attribute.new(arel_table_for(options[:from] || table_name),
+ Arel::Attribute.new(arel_table(options[:from] || table_name),
options[:select] || column_name)
else
Arel::SqlLiteral.new(options[:select] ||
Please sign in to comment.
Something went wrong with that request. Please try again.