aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-06-10 17:31:26 -0300
committerEmilio Tagua <miloops@gmail.com>2009-06-10 17:31:26 -0300
commit7be3e3ba0547587313d87bccb788a8466a62628a (patch)
treef33a86c4de5d2176c2930bcae0a5f9145883e278 /activerecord/lib/active_record
parent8c3b8323f57d366fc308e773b286a1847552b0a3 (diff)
downloadrails-7be3e3ba0547587313d87bccb788a8466a62628a.tar.gz
rails-7be3e3ba0547587313d87bccb788a8466a62628a.tar.bz2
rails-7be3e3ba0547587313d87bccb788a8466a62628a.zip
Use ARel in SQL generation through associations
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb38
1 files changed, 28 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index adc7f5335d..f0f70e0636 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -839,26 +839,44 @@ module ActiveRecord #:nodoc:
# # Update all books that match our conditions, but limit it to 5 ordered by date
# Book.update_all "author = 'David'", "title LIKE '%Rails%'", :order => 'created_at', :limit => 5
def update_all(updates, conditions = nil, options = {})
- sql = "UPDATE #{quoted_table_name} SET #{sanitize_sql_for_assignment(updates)} "
+ # sql = "UPDATE #{quoted_table_name} SET #{sanitize_sql_for_assignment(updates)} "
- scope = scope(:find)
+ # scope = scope(:find)
+
+ # select_sql = ""
+ # add_conditions!(select_sql, conditions, scope)
+
+ # if options.has_key?(:limit) || (scope && scope[:limit])
+ # # Only take order from scope if limit is also provided by scope, this
+ # # is useful for updating a has_many association with a limit.
+ # add_order!(select_sql, options[:order], scope)
- select_sql = ""
- add_conditions!(select_sql, conditions, scope)
+ # add_limit!(select_sql, options, scope)
+ # sql.concat(connection.limited_update_conditions(select_sql, quoted_table_name, connection.quote_column_name(primary_key)))
+ # else
+ # add_order!(select_sql, options[:order], nil)
+ # sql.concat(select_sql)
+ # end
+
+ # connection.update(sql, "#{name} Update")
+ scope = scope(:find)
+ arel = arel_table
+ arel = arel.where(Arel::SqlLiteral.new(construct_conditions(conditions, scope))) if conditions || scope
if options.has_key?(:limit) || (scope && scope[:limit])
# Only take order from scope if limit is also provided by scope, this
# is useful for updating a has_many association with a limit.
- add_order!(select_sql, options[:order], scope)
+ arel = arel.order(construct_order(options[:order], scope))
- add_limit!(select_sql, options, scope)
- sql.concat(connection.limited_update_conditions(select_sql, quoted_table_name, connection.quote_column_name(primary_key)))
+ arel = arel.take(construct_limit(options, scope))
+ #arel = arel.where(connection.limited_update_conditions(select_sql, quoted_table_name, connection.quote_column_name(primary_key)))
+ #sql.concat(connection.limited_update_conditions(select_sql, quoted_table_name, connection.quote_column_name(primary_key)))
else
- add_order!(select_sql, options[:order], nil)
- sql.concat(select_sql)
+ arel = arel.order(construct_order(options[:order], nil))
+ #sql.concat(select_sql)
end
- connection.update(sql, "#{name} Update")
+ arel.update(sanitize_sql_for_assignment(updates))
end
# Destroys the records matching +conditions+ by instantiating each