ce830d3c60
`delete_all` doesn't support limit, so you'd need to subquery that. And instead of subquerying with `where(id: query)`, it's better to use an `INNER JOIN`. This method also works with MySQL, while subquerying doesn't (without another layer of subquerying) Reference: https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql-doesnt-yet-support-limit-in-all-any-some-subqu/17892886#17892886
17 lines
458 B
Ruby
17 lines
458 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe Gitlab::Database::Subquery do
|
|
describe '.self_join' do
|
|
set(:project) { create(:project) }
|
|
|
|
it 'allows you to delete_all rows with WHERE and LIMIT' do
|
|
events = create_list(:event, 8, project: project)
|
|
|
|
expect do
|
|
described_class.self_join(Event.where('id < ?', events[5]).recent.limit(2)).delete_all
|
|
end.to change { Event.count }.by(-2)
|
|
end
|
|
end
|
|
end
|