Skip to content

Commit

Permalink
Fix issue with distinct alias when multiple databases used
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Nov 21, 2024
1 parent 13ad9cd commit f64d91d
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,16 @@ def add_timestamps(table_name, **options)

def columns_for_distinct(columns, orders)
order_columns = orders.reject(&:blank?).map { |s|
s = s.to_sql unless s.is_a?(String)
s = visitor.compile(s) unless s.is_a?(String)
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
.gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
}
.reject(&:blank?)
.reject { |s| columns.include?(s) }

(order_columns << super).join(", ")
order_columns_aliased = order_columns.map.with_index { |column, i| "#{column} AS alias_#{i}" }

(order_columns_aliased << super).join(", ")
end

def update_table_definition(table_name, base)
Expand Down

0 comments on commit f64d91d

Please sign in to comment.