closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

reason for with_ancestor method using map

Open ggLee6352 opened this issue 3 years ago • 0 comments

# lib/closure_tree/finders.rb

def with_ancestor(*ancestors)
  ancestor_ids = ancestors.map { |ea| ea.is_a?(ActiveRecord::Base) ? ea._ct_id : ea }
  scope = ancestor_ids.blank? ? all : joins(:ancestor_hierarchies).
    where("#{_ct.hierarchy_table_name}.ancestor_id" => ancestor_ids).
    where("#{_ct.hierarchy_table_name}.generations > 0").
    readonly(false)
  _ct.scope_with_order(scope)
end

def with_ancestor(*ancestors)
  scope = ancestor_ids.blank? ? all : joins(:ancestor_hierarchies).
    where("#{_ct.hierarchy_table_name}.ancestor_id" => ancestor_ids).
    where("#{_ct.hierarchy_table_name}.generations > 0").
    readonly(false)
  _ct.scope_with_order(scope)
end

seem to be the same

ggLee6352 avatar Sep 14 '22 10:09 ggLee6352