File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
lib/active_record/connection_adapters
spec/active_record/connection_adapters Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -747,3 +747,26 @@ def bind_string(name, value)
747747module ActiveRecord
748748 autoload :OracleEnhancedProcedures , "active_record/connection_adapters/oracle_enhanced/procedures"
749749end
750+
751+ # Backport #2070 into relese60 branch by adding some dirty monkey patch
752+ # Because #2002 has been merged to release61 branch or newer, not available for release60 branch.
753+ module Arel # :nodoc: all
754+ module Visitors
755+ class Oracle < Arel ::Visitors ::ToSql
756+ private
757+ def build_subselect ( key , o )
758+ stmt = super
759+ stmt . orders = [ ] # `orders` will never be set to prevent `ORA-00907`.
760+ stmt
761+ end
762+ end
763+ class Oracle12 < Arel ::Visitors ::ToSql
764+ private
765+ def build_subselect ( key , o )
766+ stmt = super
767+ stmt . orders = [ ] # `orders` will never be set to prevent `ORA-00907`.
768+ stmt
769+ end
770+ end
771+ end
772+ end
Original file line number Diff line number Diff line change @@ -150,6 +150,45 @@ class ::TestEmployee2 < ActiveRecord::Base
150150 end
151151 end
152152
153+ describe "`has_many` assoc has `dependent: :delete_all` with `order`" do
154+ before ( :all ) do
155+ schema_define do
156+ create_table :test_posts do |t |
157+ t . string :title
158+ end
159+ create_table :test_comments do |t |
160+ t . integer :test_post_id
161+ t . string :description
162+ end
163+ add_index :test_comments , :test_post_id
164+ end
165+ class ::TestPost < ActiveRecord ::Base
166+ has_many :test_comments , -> { order ( :id ) } , dependent : :delete_all
167+ end
168+ class ::TestComment < ActiveRecord ::Base
169+ belongs_to :test_post
170+ end
171+ TestPost . transaction do
172+ post = TestPost . create! ( title : "Title" )
173+ TestComment . create! ( test_post_id : post . id , description : "Description" )
174+ end
175+ end
176+
177+ after ( :all ) do
178+ schema_define do
179+ drop_table :test_comments
180+ drop_table :test_posts
181+ end
182+ Object . send ( :remove_const , "TestPost" )
183+ Object . send ( :remove_const , "TestComment" )
184+ ActiveRecord ::Base . clear_cache!
185+ end
186+
187+ it "should not occur `ActiveRecord::StatementInvalid: OCIError: ORA-00907: missing right parenthesis`" do
188+ expect { TestPost . first . destroy } . not_to raise_error
189+ end
190+ end
191+
153192 describe "eager loading" do
154193 before ( :all ) do
155194 schema_define do
You can’t perform that action at this time.
0 commit comments