mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactors to work with latest Arel implementation.
This commit is contained in:
parent
b3d4054692
commit
522711952b
8 changed files with 27 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
2
arel
2
arel
|
@ -1 +1 @@
|
|||
Subproject commit 4b8526dddd6a906a1879ec786401070b3545d7f4
|
||||
Subproject commit c55226bac0cfac67081b01860baa61f3acbb2ca9
|
Loading…
Reference in a new issue