mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor to calculations. Migration's versions are string not integer. ARel submodule updated.
This commit is contained in:
parent
118b19a9fa
commit
8885b2d6c1
4 changed files with 24 additions and 25 deletions
|
@ -170,12 +170,12 @@ module ActiveRecord
|
|||
elsif !options[:select].blank?
|
||||
column_name = options[:select]
|
||||
end
|
||||
construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).count(options[:distinct]))).select_value
|
||||
construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).count(options[:distinct])))
|
||||
else
|
||||
construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).send(operation))).select_value
|
||||
construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).send(operation)))
|
||||
end
|
||||
|
||||
type_cast_calculated_value(value, column_for(column_name), operation)
|
||||
type_cast_calculated_value(connection.select_value(value.to_sql), column_for(column_name), operation)
|
||||
end
|
||||
|
||||
def execute_grouped_calculation(operation, column_name, options) #:nodoc:
|
||||
|
@ -190,12 +190,11 @@ module ActiveRecord
|
|||
|
||||
aggregate_alias = column_alias_for(operation, column_name)
|
||||
|
||||
if operation == 'count' && column_name == :all
|
||||
options[:select] = "COUNT(*) AS count_all, #{group_field} AS #{group_alias}"
|
||||
else
|
||||
arel_column = Arel::Attribute.new(arel_table, column_name).send(operation)
|
||||
options[:select] = "#{arel_column.as(aggregate_alias).to_sql}, #{group_field} AS #{group_alias}"
|
||||
end
|
||||
options[:select] = (operation == 'count' && column_name == :all) ?
|
||||
"COUNT(*) AS count_all" :
|
||||
Arel::Attribute.new(arel_table, column_name).send(operation).as(aggregate_alias).to_sql
|
||||
|
||||
options[:select] << ", #{group_field} AS #{group_alias}"
|
||||
|
||||
calculated_data = connection.select_all(construct_calculation_arel(options).to_sql)
|
||||
|
||||
|
|
|
@ -410,7 +410,7 @@ module ActiveRecord
|
|||
|
||||
def get_all_versions
|
||||
table = Arel(schema_migrations_table_name)
|
||||
table.project(table['version']).select_values.map(&:to_i).sort
|
||||
Base.connection.select_values(table.project(table['version']).to_sql).map(&:to_i).sort
|
||||
end
|
||||
|
||||
def current_version
|
||||
|
@ -535,11 +535,11 @@ module ActiveRecord
|
|||
|
||||
@migrated_versions ||= []
|
||||
if down?
|
||||
@migrated_versions.delete(version.to_i)
|
||||
table.where(table["version"].eq(version)).delete
|
||||
@migrated_versions.delete(version)
|
||||
table.where(table["version"].eq(version.to_s)).delete
|
||||
else
|
||||
@migrated_versions.push(version.to_i).sort!
|
||||
table.insert table["version"] => version
|
||||
@migrated_versions.push(version).sort!
|
||||
table.insert table["version"] => version.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
|
2
arel
2
arel
|
@ -1 +1 @@
|
|||
Subproject commit de843c86518e4ac871d4bb5b0873bb6c184ac304
|
||||
Subproject commit a7dea38204f3c40e4d0c3f29ebe17af818659697
|
Loading…
Reference in a new issue