Fix APIv2 does not rewire parents correctly

pull/1481/head
Ion Biziiac 11 years ago
parent d637354013
commit 4a13ce44c3
  1. 2
      app/controllers/api/v2/planning_elements_controller.rb

@ -321,7 +321,7 @@ module Api
# re-wire the parent of this pe to the first ancestor found in the filtered set # re-wire the parent of this pe to the first ancestor found in the filtered set
# re-wiring is only needed, when there is actually a parent, and the parent has been filtered out # re-wiring is only needed, when there is actually a parent, and the parent has been filtered out
if pe.parent_id && !filtered_ids.include?(pe.parent_id) if pe.parent_id && !filtered_ids.include?(pe.parent_id)
ancestors = @planning_elements.select{|candidate| candidate.lft < pe.lft && candidate.rgt > pe.rgt } ancestors = @planning_elements.select{|candidate| candidate.lft < pe.lft && candidate.rgt > pe.rgt && candidate.root_id == pe.root_id }
# the greatest lower boundary is the first ancestor not filtered # the greatest lower boundary is the first ancestor not filtered
pe.parent_id = ancestors.empty? ? nil : ancestors.sort_by{|ancestor| ancestor.lft }.last.id pe.parent_id = ancestors.empty? ? nil : ancestors.sort_by{|ancestor| ancestor.lft }.last.id
end end

Loading…
Cancel
Save