Skip to content

Commit ce25cf1

Browse files
committed
harumph, inverse doesn't seem to fix it. :\
1 parent d0b36bc commit ce25cf1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/closure_tree/model.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module Model
77
included do
88
belongs_to :parent,
99
: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
1112

1213
attr_accessible :parent if _ct.use_attr_accessible?
1314

@@ -16,7 +17,9 @@ module Model
1617
has_many :children, *_ct.has_many_with_order_option(
1718
:class_name => _ct.model_class.to_s,
1819
:foreign_key => _ct.parent_column_name,
19-
:dependent => _ct.options[:dependent])
20+
:dependent => _ct.options[:dependent],
21+
:inverse_of => :parent)
22+
2023

2124
has_many :ancestor_hierarchies, *_ct.has_many_without_order_option(
2225
:class_name => _ct.hierarchy_class_name,

spec/label_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ def create_preorder_tree(suffix = "")
8484
end
8585
end
8686

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+
8798
context "DateLabel" do
8899
it "should find or create by path" do
89100
date = DateLabel.find_or_create_by_path(%w{2011 November 23})

0 commit comments

Comments
 (0)