Skip to content

Commit f3d8732

Browse files
committed
Fixes another issue related to ancestors in ordered trees. Closes benedikt#39
1 parent 4f87cbc commit f3d8732

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/mongoid/tree/ordering.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module Ordering
4747
#
4848
# @return [Mongoid::Criteria] Mongoid criteria to retrieve the document's ancestors
4949
def ancestors
50-
base_class.unscoped.where(:_id.in => parent_ids)
50+
base_class.unscoped { super }
5151
end
5252

5353
##

spec/mongoid/tree/ordering_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@
177177

178178
node(:leaf).ancestors.to_a.should == [node(:root), node(:level_1_b), node(:level_2_a)]
179179
end
180+
181+
it "should return the ancestors in correct order even after rearranging" do
182+
setup_tree <<-ENDTREE
183+
- root:
184+
- child:
185+
- subchild
186+
ENDTREE
187+
188+
child = node(:child); child.parent = nil; child.save!
189+
root = node(:root); root.parent = node(:child); root.save!
190+
subchild = node(:subchild); subchild.parent = root; subchild.save!
191+
192+
subchild.ancestors.to_a.should == [child, root]
193+
end
180194
end
181195
end
182196

0 commit comments

Comments
 (0)