acts_as_dag 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/acts_as_dag/acts_as_dag.rb +6 -6
- data/spec/acts_as_dag_spec.rb +1 -9
- metadata +2 -2
@@ -48,24 +48,24 @@ module ActsAsDAG
|
|
48
48
|
# Ancestors and descendants returned *include* self, e.g. A's descendants are [A,B,C,D]
|
49
49
|
# Ancestors must always be returned in order of most distant to least
|
50
50
|
# Descendants must always be returned in order of least distant to most
|
51
|
-
# NOTE:
|
51
|
+
# NOTE: Rails 4.0.0 currently ignores the order clause when eager loading, so results may not be returned in the correct order
|
52
|
+
# NOTE: multiple instances of the same descendant/ancestor may be returned if there are multiple paths from ancestor to descendant
|
52
53
|
# A
|
53
54
|
# / \
|
54
55
|
# B C
|
55
56
|
# \ /
|
56
57
|
# D
|
57
58
|
#
|
58
|
-
has_many :ancestors, lambda {
|
59
|
-
has_many :descendants, lambda {
|
59
|
+
has_many :ancestors, lambda { order("#{descendant_class.table_name}.distance DESC") }, :through => :ancestor_links, :source => :ancestor
|
60
|
+
has_many :descendants, lambda { order("#{descendant_class.table_name}.distance ASC") }, :through => :descendant_links, :source => :descendant
|
60
61
|
|
61
62
|
has_many :ancestor_links, lambda { where options[:link_conditions] }, :class_name => descendant_class, :foreign_key => 'descendant_id', :dependent => :delete_all
|
62
63
|
has_many :descendant_links, lambda { where options[:link_conditions] }, :class_name => descendant_class, :foreign_key => 'ancestor_id', :dependent => :delete_all
|
63
64
|
|
64
|
-
has_many :parent_links, lambda { where options[:link_conditions] }, :class_name => link_class, :foreign_key => 'child_id', :dependent => :delete_all
|
65
|
-
has_many :child_links, lambda { where options[:link_conditions] }, :class_name => link_class, :foreign_key => 'parent_id', :dependent => :delete_all
|
66
|
-
|
67
65
|
has_many :parents, :through => :parent_links, :source => :parent
|
68
66
|
has_many :children, :through => :child_links, :source => :child
|
67
|
+
has_many :parent_links, lambda { where options[:link_conditions] }, :class_name => link_class, :foreign_key => 'child_id', :dependent => :delete_all
|
68
|
+
has_many :child_links, lambda { where options[:link_conditions] }, :class_name => link_class, :foreign_key => 'parent_id', :dependent => :delete_all
|
69
69
|
|
70
70
|
# NOTE: Use select to prevent ActiveRecord::ReadOnlyRecord if the returned records are modified
|
71
71
|
scope :roots, lambda { select("#{table_name}.*").joins(:parent_links).where(link_class.table_name => {:parent_id => nil}) }
|
data/spec/acts_as_dag_spec.rb
CHANGED
@@ -171,7 +171,7 @@ describe 'acts_as_dag' do
|
|
171
171
|
@big_totem_pole_model.reload.children.should == [@big_red_model_totem_pole]
|
172
172
|
end
|
173
173
|
|
174
|
-
describe "when there is a single long inheritance chain
|
174
|
+
describe "when there is a single long inheritance chain" do
|
175
175
|
before(:each) do
|
176
176
|
@totem.add_child(@totem_pole)
|
177
177
|
@totem_pole.add_child(@big_totem_pole)
|
@@ -179,14 +179,6 @@ describe 'acts_as_dag' do
|
|
179
179
|
@big_model_totem_pole.add_child(@big_red_model_totem_pole)
|
180
180
|
end
|
181
181
|
|
182
|
-
it "should not return multiple instances of any descendants" do
|
183
|
-
@totem.descendants.should == [@totem, @totem_pole, @big_totem_pole, @big_model_totem_pole, @big_red_model_totem_pole]
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should not return multiple instances of any ancestors" do
|
187
|
-
@big_red_model_totem_pole.ancestors.should == [@totem, @totem_pole, @big_totem_pole, @big_model_totem_pole, @big_red_model_totem_pole]
|
188
|
-
end
|
189
|
-
|
190
182
|
describe "and we are reorganizing the middle of the chain" do
|
191
183
|
# Totem
|
192
184
|
# |
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_dag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|