1
0
Fork 0
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:
Emilio Tagua 2009-05-06 14:16:03 -03:00
parent 118b19a9fa
commit 8885b2d6c1
4 changed files with 24 additions and 25 deletions

View file

@ -170,12 +170,12 @@ module ActiveRecord
elsif !options[:select].blank? elsif !options[:select].blank?
column_name = options[:select] column_name = options[:select]
end 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 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 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 end
def execute_grouped_calculation(operation, column_name, options) #:nodoc: def execute_grouped_calculation(operation, column_name, options) #:nodoc:
@ -190,12 +190,11 @@ module ActiveRecord
aggregate_alias = column_alias_for(operation, column_name) aggregate_alias = column_alias_for(operation, column_name)
if operation == 'count' && column_name == :all options[:select] = (operation == 'count' && column_name == :all) ?
options[:select] = "COUNT(*) AS count_all, #{group_field} AS #{group_alias}" "COUNT(*) AS count_all" :
else Arel::Attribute.new(arel_table, column_name).send(operation).as(aggregate_alias).to_sql
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}" options[:select] << ", #{group_field} AS #{group_alias}"
end
calculated_data = connection.select_all(construct_calculation_arel(options).to_sql) calculated_data = connection.select_all(construct_calculation_arel(options).to_sql)

View file

@ -410,7 +410,7 @@ module ActiveRecord
def get_all_versions def get_all_versions
table = Arel(schema_migrations_table_name) 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 end
def current_version def current_version
@ -535,11 +535,11 @@ module ActiveRecord
@migrated_versions ||= [] @migrated_versions ||= []
if down? if down?
@migrated_versions.delete(version.to_i) @migrated_versions.delete(version)
table.where(table["version"].eq(version)).delete table.where(table["version"].eq(version.to_s)).delete
else else
@migrated_versions.push(version.to_i).sort! @migrated_versions.push(version).sort!
table.insert table["version"] => version table.insert table["version"] => version.to_s
end end
end end

2
arel

@ -1 +1 @@
Subproject commit de843c86518e4ac871d4bb5b0873bb6c184ac304 Subproject commit a7dea38204f3c40e4d0c3f29ebe17af818659697