File tree 2 files changed +6
-5
lines changed
2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ module Model
20
20
:dependent => _ct . options [ :dependent ] ,
21
21
:inverse_of => :parent )
22
22
23
-
24
23
has_many :ancestor_hierarchies , *_ct . has_many_without_order_option (
25
24
:class_name => _ct . hierarchy_class_name ,
26
25
:foreign_key => "descendant_id" ,
@@ -49,12 +48,14 @@ def _ct
49
48
50
49
# Returns true if this node has no parents.
51
50
def root?
52
- _ct_parent_id . nil?
51
+ # Accessing the parent will fetch that row from the database,
52
+ # so if we are persisted, just check that the parent_id column is nil.
53
+ persisted? ? _ct_parent_id . nil? : parent . nil?
53
54
end
54
55
55
56
# Returns true if this node has a parent, and is not a root.
56
57
def child?
57
- !parent . nil ?
58
+ !root ?
58
59
end
59
60
60
61
# Returns true if this node has no children.
Original file line number Diff line number Diff line change @@ -86,8 +86,8 @@ def create_preorder_tree(suffix = "")
86
86
87
87
context "Parent/child inverse relationships" do
88
88
it "should associate both sides of the parent and child relationships" do
89
- parent = Label . new ( :name => '123 ' )
90
- child = parent . children . build
89
+ parent = Label . new ( :name => 'parent ' )
90
+ child = parent . children . build ( :name => 'child' )
91
91
parent . should be_root
92
92
parent . should_not be_leaf
93
93
child . should_not be_root
You can’t perform that action at this time.
0 commit comments