mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Split arel_table into method to get a relation and another to memoize the default relation.
This commit is contained in:
parent
0da71980cd
commit
bd51790895
5 changed files with 13 additions and 13 deletions
|
@ -1698,7 +1698,7 @@ module ActiveRecord
|
|||
def construct_finder_arel_with_included_associations(options, join_dependency)
|
||||
scope = scope(:find)
|
||||
|
||||
relation = arel_table((scope && scope[:from]) || options[:from])
|
||||
relation = arel_table_for((scope && scope[:from]) || options[:from])
|
||||
|
||||
for association in join_dependency.join_associations
|
||||
relation = association.join_relation(relation)
|
||||
|
@ -1741,7 +1741,7 @@ module ActiveRecord
|
|||
def construct_finder_sql_for_association_limiting(options, join_dependency)
|
||||
scope = scope(:find)
|
||||
|
||||
relation = arel_table(options[:from])
|
||||
relation = arel_table_for(options[:from])
|
||||
|
||||
for association in join_dependency.join_associations
|
||||
relation = association.join_relation(relation)
|
||||
|
|
|
@ -56,7 +56,7 @@ module ActiveRecord
|
|||
if @reflection.options[:insert_sql]
|
||||
@owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
|
||||
else
|
||||
relation = arel_table(@reflection.options[:join_table])
|
||||
relation = arel_table_for(@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 @@ module ActiveRecord
|
|||
if sql = @reflection.options[:delete_sql]
|
||||
records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
|
||||
else
|
||||
relation = arel_table(@reflection.options[:join_table])
|
||||
relation = arel_table_for(@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
|
||||
|
|
|
@ -69,7 +69,7 @@ module ActiveRecord
|
|||
when :delete_all
|
||||
@reflection.klass.delete(records.map { |record| record.id })
|
||||
else
|
||||
relation = arel_table(@reflection.table_name)
|
||||
relation = arel_table_for(@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)
|
||||
|
|
|
@ -1493,11 +1493,11 @@ module ActiveRecord #:nodoc:
|
|||
|
||||
|
||||
def arel_table(table = nil)
|
||||
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
|
||||
@arel_table ||= arel_table_for(table_name)
|
||||
end
|
||||
|
||||
def arel_table_for(table_name)
|
||||
Relation.new(self, Arel::Table.new(table_name))
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -1666,7 +1666,7 @@ module ActiveRecord #:nodoc:
|
|||
|
||||
def construct_finder_arel(options = {}, scope = scope(:find))
|
||||
# TODO add lock to Arel
|
||||
relation = arel_table(options[:from]).
|
||||
relation = arel_table_for(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]))).
|
||||
|
|
|
@ -146,7 +146,7 @@ module ActiveRecord
|
|||
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(options[:from]).
|
||||
relation = arel_table_for(options[:from]).
|
||||
joins(construct_join(options[:joins], scope)).
|
||||
conditions(construct_conditions(options[:conditions], scope)).
|
||||
order(options[:order]).
|
||||
|
@ -164,7 +164,7 @@ module ActiveRecord
|
|||
|
||||
def execute_simple_calculation(operation, column_name, options, relation) #:nodoc:
|
||||
column = if column_names.include?(column_name.to_s)
|
||||
Arel::Attribute.new(arel_table(options[:from] || table_name),
|
||||
Arel::Attribute.new(arel_table_for(options[:from] || table_name),
|
||||
options[:select] || column_name)
|
||||
else
|
||||
Arel::SqlLiteral.new(options[:select] ||
|
||||
|
|
Loading…
Reference in a new issue