diff --git a/lib/closure_tree/model.rb b/lib/closure_tree/model.rb index 4dd5cf0a..7af08eb2 100644 --- a/lib/closure_tree/model.rb +++ b/lib/closure_tree/model.rb @@ -13,7 +13,7 @@ module Model touch: _ct.options[:touch], optional: true) - order_by_generations = "#{_ct.quoted_hierarchy_table_name}.generations asc" + order_by_generations = Arel.sql("#{_ct.quoted_hierarchy_table_name}.generations ASC") has_many :children, *_ct.has_many_with_order_option( class_name: _ct.model_class.to_s, diff --git a/lib/closure_tree/numeric_deterministic_ordering.rb b/lib/closure_tree/numeric_deterministic_ordering.rb index f5a98200..b45914e8 100644 --- a/lib/closure_tree/numeric_deterministic_ordering.rb +++ b/lib/closure_tree/numeric_deterministic_ordering.rb @@ -65,7 +65,7 @@ def _ct_sum_order_by(node = nil) node_score = "(1 + anc.#{_ct.quoted_order_column(false)}) * " + "power(#{h['total_descendants']}, #{h['max_depth'].to_i + 1} - #{depth_column})" - "sum(#{node_score})" + Arel.sql("SUM(#{node_score})") end def roots_and_descendants_preordered