Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/arel/visitors/oracle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ def is_distinct_from(o, collector)
collector = visit [o.left, o.right, 0, 1], collector
collector << ")"
end

# Oracle will occur an error `ORA-00907: missing right parenthesis`
# when using `ORDER BY` in `UPDATE` or `DELETE`'s subquery.
#
# This method has been overridden based on the following code.
# https://github.com/rails/rails/blob/v6.1.0.rc1/activerecord/lib/arel/visitors/to_sql.rb#L815-L825
def build_subselect(key, o)
stmt = super
stmt.orders = [] # `orders` will never be set to prevent `ORA-00907`.
stmt
end
end
end
end
11 changes: 11 additions & 0 deletions lib/arel/visitors/oracle12.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ def is_distinct_from(o, collector)
collector = visit [o.left, o.right, 0, 1], collector
collector << ")"
end

# Oracle will occur an error `ORA-00907: missing right parenthesis`
# when using `ORDER BY` in `UPDATE` or `DELETE`'s subquery.
#
# This method has been overridden based on the following code.
# https://github.com/rails/rails/blob/v6.1.0.rc1/activerecord/lib/arel/visitors/to_sql.rb#L815-L825
def build_subselect(key, o)
stmt = super
stmt.orders = [] # `orders` will never be set to prevent `ORA-00907`.
stmt
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,45 @@ class ::TestEmployee2 < ActiveRecord::Base
end
end

describe "`has_many` assoc has `dependent: :delete_all` with `order`" do
before(:all) do
schema_define do
create_table :test_posts do |t|
t.string :title
end
create_table :test_comments do |t|
t.integer :test_post_id
t.string :description
end
add_index :test_comments, :test_post_id
end
class ::TestPost < ActiveRecord::Base
has_many :test_comments, -> { order(:id) }, dependent: :delete_all
end
class ::TestComment < ActiveRecord::Base
belongs_to :test_post
end
TestPost.transaction do
post = TestPost.create!(title: "Title")
TestComment.create!(test_post_id: post.id, description: "Description")
end
end

after(:all) do
schema_define do
drop_table :test_comments
drop_table :test_posts
end
Object.send(:remove_const, "TestPost")
Object.send(:remove_const, "TestComment")
ActiveRecord::Base.clear_cache!
end

it "should not occur `ActiveRecord::StatementInvalid: OCIError: ORA-00907: missing right parenthesis`" do
expect { TestPost.first.destroy }.not_to raise_error
end
end

describe "eager loading" do
before(:all) do
schema_define do
Expand Down