mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed columns_for_distinct
of postgresql adapter
This commit is contained in:
parent
e90f0e0eb6
commit
1cb52a1733
3 changed files with 17 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
* Fixed `columns_for_distinct` of postgresql adapter to work correctly
|
||||||
|
with orders without sort direction modifiers.
|
||||||
|
|
||||||
|
*Nikolay Kondratyev*
|
||||||
|
|
||||||
* Assign inet/cidr attribute with `nil` value for invalid address.
|
* Assign inet/cidr attribute with `nil` value for invalid address.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
|
@ -475,7 +475,7 @@ module ActiveRecord
|
||||||
# Convert Arel node to string
|
# Convert Arel node to string
|
||||||
s = s.to_sql unless s.is_a?(String)
|
s = s.to_sql unless s.is_a?(String)
|
||||||
# Remove any ASC/DESC modifiers
|
# Remove any ASC/DESC modifiers
|
||||||
s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '')
|
s.gsub(/\s+(?:ASC|DESC)?\s*(?:NULLS\s+(?:FIRST|LAST)\s*)?/i, '')
|
||||||
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
|
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
|
||||||
|
|
||||||
[super, *order_columns].join(', ')
|
[super, *order_columns].join(', ')
|
||||||
|
|
|
@ -259,6 +259,17 @@ module ActiveRecord
|
||||||
assert_equal "posts.title, posts.updater_id AS alias_0", @connection.columns_for_distinct("posts.title", ["posts.updater_id desc nulls last"])
|
assert_equal "posts.title, posts.updater_id AS alias_0", @connection.columns_for_distinct("posts.title", ["posts.updater_id desc nulls last"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_columns_for_distinct_without_order_specifiers
|
||||||
|
assert_equal "posts.title, posts.updater_id AS alias_0",
|
||||||
|
@connection.columns_for_distinct("posts.title", ["posts.updater_id"])
|
||||||
|
|
||||||
|
assert_equal "posts.title, posts.updater_id AS alias_0",
|
||||||
|
@connection.columns_for_distinct("posts.title", ["posts.updater_id nulls last"])
|
||||||
|
|
||||||
|
assert_equal "posts.title, posts.updater_id AS alias_0",
|
||||||
|
@connection.columns_for_distinct("posts.title", ["posts.updater_id nulls first"])
|
||||||
|
end
|
||||||
|
|
||||||
def test_raise_error_when_cannot_translate_exception
|
def test_raise_error_when_cannot_translate_exception
|
||||||
assert_raise TypeError do
|
assert_raise TypeError do
|
||||||
@connection.send(:log, nil) { @connection.execute(nil) }
|
@connection.send(:log, nil) { @connection.execute(nil) }
|
||||||
|
|
Loading…
Reference in a new issue