allow delete all on inner join with aliased scope

test plan
 - specs should pass

Change-Id: I37857a560d3159c77706bfc737e71c7ac62c3428
Reviewed-on: https://gerrit.instructure.com/25771
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2013-10-29 12:35:44 -06:00
parent 9cae25c185
commit 9cfd6dc9e1
2 changed files with 13 additions and 1 deletions

View File

@ -679,7 +679,7 @@ class ActiveRecord::Base
join_conditions = []
joins_sql.strip.split('INNER JOIN')[1..-1].each do |join|
# this could probably be improved
raise "PostgreSQL update_all/delete_all only supports INNER JOIN" unless join.strip =~ /([a-zA-Z'"_]+)\s+ON\s+(.*)/
raise "PostgreSQL update_all/delete_all only supports INNER JOIN" unless join.strip =~ /([a-zA-Z'"_]+(?:(?: [aA][sS])? [a-zA-Z_])?)\s+ON\s+(.*)/
tables << $1
join_conditions << $2
end

View File

@ -44,5 +44,17 @@ module ActiveRecord
end
end
describe "deconstruct_joins" do
describe "delete_all" do
it "should allow delete all on inner join with alias" do
User.create(name: 'dr who')
User.create(name: 'dr who')
expect { User.joins("INNER JOIN users u ON users.sortable_name = u.sortable_name").
where("u.sortable_name <> users.sortable_name").delete_all }.to_not raise_error
end
end
end
end
end