closure_tree 3.4.2 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -323,6 +323,10 @@ Closure tree is [tested under every combination](http://travis-ci.org/#!/mceache
323
323
 
324
324
  ## Change log
325
325
 
326
+ ### 3.4.3
327
+
328
+ * Fixed [issue 19](https://github.com/mceachen/closure_tree/issues/19), which caused
329
+ ```self_and_siblings``` to fail if ```parent_id``` was not the ```parent_column_name```
326
330
 
327
331
  ### 3.4.2
328
332
 
@@ -88,19 +88,15 @@ module ClosureTree
88
88
  end
89
89
 
90
90
  def self.leaves
91
- s = joins(leaves_join_sql)
92
- order_option ? s.order(order_option) : s
93
- end
94
-
95
- def self.leaves_join_sql
96
- <<-SQL
97
- INNER JOIN
98
- (SELECT ancestor_id
99
- FROM #{quoted_hierarchy_table_name}
100
- GROUP BY 1
101
- HAVING MAX(#{quoted_hierarchy_table_name}.generations) = 0) AS leaves
102
- ON (#{quoted_table_name}.#{primary_key} = leaves.ancestor_id)
91
+ s = joins(<<-SQL)
92
+ INNER JOIN (
93
+ SELECT ancestor_id
94
+ FROM #{quoted_hierarchy_table_name}
95
+ GROUP BY 1
96
+ HAVING MAX(#{quoted_hierarchy_table_name}.generations) = 0
97
+ ) AS leaves ON (#{quoted_table_name}.#{primary_key} = leaves.ancestor_id)
103
98
  SQL
99
+ order_option ? s.order(order_option) : s
104
100
  end
105
101
  end
106
102
  end
@@ -129,14 +125,7 @@ module ClosureTree
129
125
  end
130
126
 
131
127
  def leaves
132
- return [self] if leaf?
133
- self.class.leaves.where(<<-SQL
134
- #{quoted_table_name}.#{self.class.primary_key} IN (
135
- SELECT descendant_id
136
- FROM #{quoted_hierarchy_table_name}
137
- WHERE ancestor_id = #{id})
138
- SQL
139
- )
128
+ self_and_descendants.leaves
140
129
  end
141
130
 
142
131
  def depth
@@ -169,7 +158,7 @@ module ClosureTree
169
158
  end
170
159
 
171
160
  def self_and_siblings
172
- s = self.class.scoped.where(:parent_id => parent)
161
+ s = self.class.scoped.where(parent_column_sym => parent)
173
162
  quoted_order_column ? s.order(quoted_order_column) : s
174
163
  end
175
164
 
@@ -279,6 +268,7 @@ module ClosureTree
279
268
  # The crazy double-wrapped sub-subselect works around MySQL's limitation of subselects on the same table that is being mutated.
280
269
  # It shouldn't affect performance of postgresql.
281
270
  # See http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html
271
+ # Also: PostgreSQL doesn't support INNER JOIN on DELETE, so we can't use that.
282
272
  connection.execute <<-SQL
283
273
  DELETE FROM #{quoted_hierarchy_table_name}
284
274
  WHERE descendant_id IN (
@@ -1,3 +1,3 @@
1
1
  module ClosureTree
2
- VERSION = "3.4.2" unless defined?(::ClosureTree::VERSION)
2
+ VERSION = "3.4.3" unless defined?(::ClosureTree::VERSION)
3
3
  end
@@ -47,7 +47,7 @@ ActiveRecord::Schema.define(:version => 0) do
47
47
  t.string "name"
48
48
  t.string "type"
49
49
  t.integer "sort_order"
50
- t.integer "parent_id"
50
+ t.integer "mother_id"
51
51
  end
52
52
 
53
53
  create_table "label_hierarchies", :id => false, :force => true do |t|
@@ -158,7 +158,7 @@ describe Label do
158
158
  labels(:c2).append_sibling(labels(:e2), false)
159
159
  labels(:e2).self_and_siblings.to_a.should == [labels(:b1), labels(:b2), labels(:c2), labels(:e2)]
160
160
  labels(:a1).self_and_descendants.collect(&:name).should == %w(a1 b1 b2 c2 e2 d2 c1-six c1-seven c1-eight c1-nine)
161
- labels(:a1).leaves.collect(&:name).should == %w(d2 b2 e2 c1-six c1-seven c1-eight c1-nine)
161
+ labels(:a1).leaves.collect(&:name).should == %w(b2 e2 d2 c1-six c1-seven c1-eight c1-nine)
162
162
  end
163
163
  end
164
164
  end
@@ -41,7 +41,7 @@ end
41
41
 
42
42
  class Label < ActiveRecord::Base
43
43
  attr_accessible :name # < - make sure order doesn't matter
44
- acts_as_tree :order => "sort_order"
44
+ acts_as_tree :order => "sort_order", :parent_column_name => "mother_id"
45
45
 
46
46
  def to_s
47
47
  "#{self.class}: #{name}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closure_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  segments:
194
194
  - 0
195
- hash: 2623137531718887180
195
+ hash: -1873822360950581335
196
196
  required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  none: false
198
198
  requirements:
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  segments:
203
203
  - 0
204
- hash: 2623137531718887180
204
+ hash: -1873822360950581335
205
205
  requirements: []
206
206
  rubyforge_project:
207
207
  rubygems_version: 1.8.23