Это работало с mysql и rails 2.3
# in config/initializers/active_record_extensions.rb
class ActiveRecord::Base
# like delete_all, but honors limit (either through scope ar as a option)
def self.delete_all_limit(conditions = nil, limit=nil, offset=nil)
scope = scope(:find)
sql = "DELETE FROM #{quoted_table_name} "
add_conditions!(sql, conditions, scope)
add_limit!(sql, {:limit => limit, :offset => offset}, scope)
connection.delete(sql, "#{name} Delete all limited")
end
end
и еще более уродливым хаком для oracle_enhanced adpater.(Я предполагаю, что это лучше с рельсами3)
# in config/initializers/active_record_extensions.rb
module ActiveRecord
class Base
# like delete_all, but honors limit and offset (either through scope ar as a option)
def self.delete_all_limit(conditions = nil, limit=nil, offset=nil)
scope = scope(:find)
q = self
limit ||= scope[:limit] if scope
if limit
limit = limit.to_i
q = q.scoped(:conditions => "rownum <= #{limit}")
end
return q.delete_all(conditions)
end
end
end