diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-02 11:40:01 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-02 11:40:01 -0300 |
commit | 522711952bf315bc52353e941183237a41f61b23 (patch) | |
tree | debb3e1956a6e9b61fc0ff0df8b898d984c8cbf8 /activerecord/lib | |
parent | b3d40546923b194a89be0d9e00758864fa60b9e8 (diff) | |
download | rails-522711952bf315bc52353e941183237a41f61b23.tar.gz rails-522711952bf315bc52353e941183237a41f61b23.tar.bz2 rails-522711952bf315bc52353e941183237a41f61b23.zip |
Refactors to work with latest Arel implementation.
Diffstat (limited to 'activerecord/lib')
7 files changed, 26 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 56f3bd9faa..81969d11c5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -909,7 +909,11 @@ 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 <tt>before_*</tt> or +after_destroy+ callbacks, use the +destroy_all+ method instead. def delete_all(conditions = nil) - arel_table.where(construct_conditions(conditions, scope(:find))).delete + if conditions + arel_table.where(Arel::SqlLiteral.new(construct_conditions(conditions, scope(:find)))).delete + else + arel_table.delete + end end # Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. @@ -1691,7 +1695,7 @@ module ActiveRecord #:nodoc: end def arel_table(table = table_name) - @arel_table = Arel(table) + @arel_table = Arel::Table.new(table, ActiveRecord::Base.connection) end def construct_finder_arel(options) @@ -3058,7 +3062,7 @@ module ActiveRecord #:nodoc: end def arel_table - @arel_table ||= Arel(self.class.table_name) + @arel_table ||= Arel::Table.new(self.class.table_name, ActiveRecord::Base.connection) end def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys) @@ -3069,7 +3073,7 @@ module ActiveRecord #:nodoc: value = read_attribute(name) if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name)) - attrs[arel_table[name]] = value + attrs[arel_table[name]] = value.is_a?(Hash) ? value.to_yaml : value end end end diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 98f9450662..8b8fb37d2d 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -161,19 +161,18 @@ module ActiveRecord end def execute_simple_calculation(operation, column_name, options) #:nodoc: - table = options[:from] || table_name - - value = if operation == 'count' - if column_name == :all && options[:select].blank? - column_name = "*" - 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]))) + column = if column_names.include?(column_name.to_s) + Arel::Attribute.new(arel_table(options[:from] || table_name), + options[:select] || column_name) else - construct_calculation_arel(options.merge(:select => Arel::Attribute.new(Arel(table), column_name).send(operation))) + Arel::SqlLiteral.new(options[:select] || + (column_name == :all ? "*" : column_name.to_s)) end + value = construct_calculation_arel(options.merge( + :select => operation == 'count' ? column.count(options[:distinct]) : column.send(operation) + )) + type_cast_calculated_value(connection.select_value(value.to_sql), column_for(column_name), operation) end diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 08601da00a..ce04a8109d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -53,7 +53,7 @@ module ActiveRecord def delete(sql, name = nil) delete_sql(sql, name) end - + # Checks whether there is currently no transaction active. This is done # by querying the database driver, and does not use the transaction # house-keeping information recorded by #increment_open_transactions and @@ -170,7 +170,7 @@ module ActiveRecord end end end - + # Begins the transaction (and turns off auto-committing). def begin_db_transaction() end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 0aae97a6a9..6d28e01544 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -331,6 +331,7 @@ module ActiveRecord super sql, name id_value || @connection.insert_id end + alias :create :insert_sql def update_sql(sql, name = nil) #:nodoc: super diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 4b2ddac634..763db3900d 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -486,6 +486,7 @@ module ActiveRecord end end end + alias :create :insert # create a 2D array representing the result set def result_as_array(res) #:nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index c9d0c9574f..cabb63bfaf 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -109,7 +109,7 @@ module ActiveRecord def supports_add_column? sqlite_version >= '3.1.6' end - + def disconnect! super @connection.close rescue nil @@ -181,6 +181,7 @@ module ActiveRecord def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc: super || @connection.last_insert_row_id end + alias :create :insert_sql def select_rows(sql, name = nil) execute(sql, name).map do |row| @@ -355,7 +356,7 @@ module ActiveRecord (options[:rename][column.name] || options[:rename][column.name.to_sym] || column.name) : column.name - + @definition.column(column_name, column.type, :limit => column.limit, :default => column.default, :null => column.null) diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 557ab07abf..b069736778 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -409,7 +409,7 @@ module ActiveRecord end def get_all_versions - table = Arel(schema_migrations_table_name) + table = Arel::Table.new(schema_migrations_table_name, Base.connection) Base.connection.select_values(table.project(table['version']).to_sql).map(&:to_i).sort end @@ -531,7 +531,7 @@ module ActiveRecord private def record_version_state_after_migrating(version) - table = Arel(self.class.schema_migrations_table_name) + table = Arel::Table.new(self.class.schema_migrations_table_name, Base.connection) @migrated_versions ||= [] if down? |