File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ module Model
7
7
included do
8
8
belongs_to :parent ,
9
9
:class_name => _ct . model_class . to_s ,
10
- :foreign_key => _ct . parent_column_name
10
+ :foreign_key => _ct . parent_column_name ,
11
+ :inverse_of => :children
11
12
12
13
attr_accessible :parent if _ct . use_attr_accessible?
13
14
@@ -16,7 +17,9 @@ module Model
16
17
has_many :children , *_ct . has_many_with_order_option (
17
18
:class_name => _ct . model_class . to_s ,
18
19
:foreign_key => _ct . parent_column_name ,
19
- :dependent => _ct . options [ :dependent ] )
20
+ :dependent => _ct . options [ :dependent ] ,
21
+ :inverse_of => :parent )
22
+
20
23
21
24
has_many :ancestor_hierarchies , *_ct . has_many_without_order_option (
22
25
:class_name => _ct . hierarchy_class_name ,
Original file line number Diff line number Diff line change @@ -84,6 +84,17 @@ def create_preorder_tree(suffix = "")
84
84
end
85
85
end
86
86
87
+ context "Parent/child inverse relationships" do
88
+ it "should associate both sides of the parent and child relationships" do
89
+ parent = Label . new ( :name => '123' )
90
+ child = parent . children . build
91
+ parent . should be_root
92
+ parent . should_not be_leaf
93
+ child . should_not be_root
94
+ child . should be_leaf
95
+ end
96
+ end
97
+
87
98
context "DateLabel" do
88
99
it "should find or create by path" do
89
100
date = DateLabel . find_or_create_by_path ( %w{ 2011 November 23 } )
You can’t perform that action at this time.
0 commit comments