Skip to content

Commit

Permalink
Fix ordered_by_ancestry for oracle-db (An empty string is treated as …
Browse files Browse the repository at this point in the history
…NULL in Oracle. Ordering ascending, deliver NULL-Values at the rear.)
  • Loading branch information
Florian Glaser committed Apr 16, 2021
1 parent 2ff497e commit 0483b1b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ancestry/materialized_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def ordered_by_ancestry(order = nil)
reorder(arel_table[ancestry_column], order)
elsif %w(postgresql).include?(connection.adapter_name.downcase) && ActiveRecord::VERSION::STRING >= "6.1"
reorder(Arel::Nodes::Ascending.new(arel_table[ancestry_column]).nulls_first, order)
elsif %w(oracleenhanced).include?(connection.adapter_name.downcase)
reorder(Arel.sql("#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(ancestry_column)} ASC NULLS FIRST"), order)
else
reorder(
Arel::Nodes::Ascending.new(Arel::Nodes::NamedFunction.new('COALESCE', [arel_table[ancestry_column], Arel.sql("''")])),
Expand Down

0 comments on commit 0483b1b

Please sign in to comment.