@@ -64,7 +64,7 @@ def self.replace_ancestry_sql(column, old_ancestry, new_ancestry, klass)
6464 Arel . sql ( replace_sql )
6565 end
6666
67- def self . child_ancestry_sql ( table_name , ancestry_column , primary_key , adapter )
67+ def self . child_ancestry_sql ( table_name , ancestry_column , primary_key , adapter , integer_pk : true )
6868 pk_sql = concat ( adapter , "#{ table_name } .#{ primary_key } " )
6969 full_sql = concat ( adapter , "#{ table_name } .#{ ancestry_column } " , "'#{ DELIMITER } '" , "#{ table_name } .#{ primary_key } " )
7070 %{
@@ -79,7 +79,7 @@ def self.child_ancestry_sql(table_name, ancestry_column, primary_key, adapter)
7979 def self . construct_root_id_sql ( table_name , ancestry_column , primary_key , adapter )
8080 col = table_name ? "#{ table_name } .#{ ancestry_column } " : ancestry_column . to_s
8181 pk = table_name ? "#{ table_name } .#{ primary_key } " : primary_key . to_s
82- if %w( mysql mysql2 ) . include? ( adapter )
82+ if %w( mysql mysql2 trilogy ) . include? ( adapter )
8383 "CASE WHEN #{ col } IS NULL THEN #{ pk } ELSE CAST(SUBSTRING_INDEX(#{ col } , '/', 1) AS UNSIGNED) END"
8484 elsif %w( pg postgresql postgis ) . include? ( adapter )
8585 "CASE WHEN #{ col } IS NULL THEN #{ pk } ELSE CAST(SUBSTR(#{ col } , 1, STRPOS(#{ col } ||'/', '/')-1) AS INTEGER) END"
@@ -92,7 +92,7 @@ def self.construct_root_id_sql(table_name, ancestry_column, primary_key, adapter
9292 # MP1: ancestry is NULL (root) or "1/2/3" (parent_id=3)
9393 def self . construct_parent_id_sql ( table_name , ancestry_column , adapter )
9494 col = table_name ? "#{ table_name } .#{ ancestry_column } " : ancestry_column . to_s
95- if %w( mysql mysql2 ) . include? ( adapter )
95+ if %w( mysql mysql2 trilogy ) . include? ( adapter )
9696 "CASE WHEN #{ col } IS NULL THEN NULL ELSE CAST(SUBSTRING_INDEX(#{ col } , '/', -1) AS UNSIGNED) END"
9797 else
9898 "CASE WHEN #{ col } IS NULL THEN NULL ELSE CAST(SUBSTR(#{ col } , LENGTH(RTRIM(#{ col } , REPLACE(#{ col } , '/', ''))) + 1) AS INTEGER) END"
@@ -106,7 +106,7 @@ def self.construct_depth_sql(table_name, ancestry_column)
106106
107107 # mp1 roots are NULL — need NULLS FIRST or COALESCE to sort roots before children
108108 def self . ordered_by_ancestry ( arel_column , adapter )
109- if %w( mysql mysql2 sqlite sqlite3 ) . include? ( adapter )
109+ if %w( mysql mysql2 trilogy sqlite sqlite3 ) . include? ( adapter )
110110 Arel ::Nodes ::Ascending . new ( arel_column )
111111 elsif ActiveRecord ::VERSION ::STRING >= "6.1"
112112 Arel ::Nodes ::Ascending . new ( arel_column ) . nulls_first
0 commit comments