# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 44 def primary_key table[klass.primary_key] end
class ActiveRecord::HierarchicalQuery::CTE::CycleDetector
Constants
- COLUMN_NAME
Public Class Methods
new(query)
click to toggle source
@param [ActiveRecord::HierarchicalQuery::Query] query
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 10 def initialize(query) @query = query end
Public Instance Methods
apply_to_non_recursive(arel)
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 14 def apply_to_non_recursive(arel) if enabled? arel.project Arel::Nodes::PostgresArray.new([primary_key]).as(column_name) end arel end
apply_to_recursive(arel)
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 22 def apply_to_recursive(arel) if enabled? arel.project Arel::Nodes::ArrayConcat.new(parent_column, primary_key) arel.constraints << Arel::Nodes::Not.new(primary_key.eq(any(parent_column))) end arel end
Private Instance Methods
any(argument)
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 48 def any(argument) Arel::Nodes::NamedFunction.new('ANY', [argument]) end
column_name()
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 36 def column_name COLUMN_NAME end
enabled?()
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 32 def enabled? @query.nocycle_value end
parent_column()
click to toggle source
# File lib/active_record/hierarchical_query/cte/cycle_detector.rb, line 40 def parent_column @query.recursive_table[column_name] end
primary_key()
click to toggle source