Skip to content

Commit 1c6ee6c

Browse files
committed
Fix columns_for_distinct when using Rails 6.1
Running `ARCONN=oracle bundle exec ruby -Itest ./test/cases/finder_test.rb -n test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct` in Rails 6.1.4.4 will result in an error. ``` ARCONN=oracle bundle exec ruby -Itest ./test/cases/finder_test.rb -n test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct Using oracle Warning: NLS_LANG is not set. fallback to US7ASCII. Run options: -n test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct --seed 32511 # Running: F Failure: FinderTest#test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct [./test/cases/finder_test.rb:1503]: Expected: 2 Actual: 1 rails test ./test/cases/finder_test.rb:1502 Finished in 1.275346s, 0.7841 runs/s, 0.7841 assertions/s. 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips ``` Changing the return value of `columns_for_distinct` causes the test to pass. This is a fix for the change to PostgreSQL and MySQL adapters in Rails 6.0. rails/rails#31966 The reason why the tests for `ARCONN=oracle bundle exec ruby -Itest ./test/cases/finder_test.rb -n test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct` don't pass is because of a fix in finder_methods.rb in Rails 6.1. rails/rails@2ad2425
1 parent afe43fa commit 1c6ee6c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/active_record/connection_adapters/oracle_enhanced_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def columns_for_distinct(columns, orders) # :nodoc:
662662
}.reject(&:blank?).map.with_index { |column, i|
663663
"FIRST_VALUE(#{column}) OVER (PARTITION BY #{columns} ORDER BY #{column}) AS alias_#{i}__"
664664
}
665-
[super, *order_columns].join(", ")
665+
(order_columns << super).join(", ")
666666
end
667667

668668
def temporary_table?(table_name) # :nodoc:

0 commit comments

Comments
 (0)