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:
parent
9cae25c185
commit
9cfd6dc9e1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue