awesome_nested_set 3.0.1 → 3.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03913da2bc68032de674546a99f3650d3f4bab01
4
- data.tar.gz: 163efbd91c3037f8b30320be60a597c598764da9
3
+ metadata.gz: 8f8c65ecba7e654a2e914de64f646e5e43416e47
4
+ data.tar.gz: c9d4bda2db60143062026f576080982698fa73ff
5
5
  SHA512:
6
- metadata.gz: 3ded8c47fca3edb7ef59fe7198e11ab661291aa0b4813a357bf6c17ac890ea6cbc4a44520e52c1622d6988867a9d75cd75a9a7d48ae7034181c3881a1636aae3
7
- data.tar.gz: a4cf617782266c5b0c29170813ed1f612d704a5d5bb3fd13c7e0f4686625d91017a3cafc3200bf4277982aedbbcff804d591cfbf20d58d6db7877466a9e605ec
6
+ metadata.gz: 98ecf4b03fd84f510f84092fe197c73b8a6612dfd80444d9c4dd79d49bdfb3f0ebb4f47966f6ce5e02aadb9006682f1d5fc5cb9c6654682fff286d0585ec1dc1
7
+ data.tar.gz: efc4897f020894d3798c6c00782baa3de7409d14f02890608da4f8245f4dfc59708ac6771efe2f1667b8b9f324c78fb3705ddee1b7df3b8d403bbdb13298f6ba
data/CHANGELOG CHANGED
@@ -1,9 +1,21 @@
1
+ 3.0.2
2
+ * Fix `dependent: :restrict_with_exception` not allowing a delete to occur. [Brendan Kilfoil]
3
+ * Replace `Arel::SelectManager#join_sql` with `Arel::SelectManager#join_sources` as `Arel::Node#joins` accepts AST as well. [Swanand Pagnis]
4
+ * Corrected nested_set_scope usage. [Finbarr Taylor] [#292](https://github.com/collectiveidea/awesome_nested_set/pull/292)
5
+ * Fix bug: when model with default_scope make #lft and #rgt wrong [eddie](https://github.com/afunction) [#281](https://github.com/collectiveidea/awesome_nested_set/pull/281)
6
+ * [Compare to 3.0.1](https://github.com/collectiveidea/awesome_nested_set/compare/v3.0.1...v3.0.2)
7
+
8
+ 3.0.1
9
+ * Fixed `dependent: :destroy` when called from associated object. #162 [Kuldeep Aggarwal]
10
+ * [Compare to 3.0.0](https://github.com/collectiveidea/awesome_nested_set/compare/v3.0.0...v3.0.1)
11
+
1
12
  3.0.0
2
13
  * Support Rails 4.1 [Micah Geisel]
3
14
  * Support dependent: restrict_with_error [Tiago Moraes]
4
15
  * Added information to the README regarding indexes to be added for performance [bdarfler]
5
16
  * Modified associate_parents to add child objects to the parent#children collection [Tiago Moraes]
6
- * Fixed `dependent: :destroy` when called from associated object. #162 [Kuldeep Aggarwal]
17
+ * Fix `dependent: :restrict_with_exception` not allowing a delete to occur. [Brendan Kilfoil]
18
+ * [Compare to v2.1.6](https://github.com/collectiveidea/awesome_nested_set/compare/v2.1.6...v3.0.0)
7
19
 
8
20
  2.1.6
9
21
  * Fixed rebuild! when there is a default_scope with order [Adrian Serafin]
data/README.md CHANGED
@@ -23,19 +23,22 @@ gem 'awesome_nested_set'
23
23
 
24
24
  ## Usage
25
25
 
26
- To make use of `awesome_nested_set`, your model needs to have 3 fields:
26
+ To make use of `awesome_nested_set` your model needs to have 3 fields:
27
27
  `lft`, `rgt`, and `parent_id`. The names of these fields are configurable.
28
- You can also have an optional field, `depth`:
28
+ You can also have optional fields: `depth` and `children_count`. These fields are configurable.
29
29
 
30
30
  ```ruby
31
31
  class CreateCategories < ActiveRecord::Migration
32
32
  def self.up
33
33
  create_table :categories do |t|
34
34
  t.string :name
35
- t.integer :parent_id
36
- t.integer :lft
37
- t.integer :rgt
38
- t.integer :depth # this is optional.
35
+ t.integer :parent_id, :null => true, :index => true
36
+ t.integer :lft, :null => false, :index => true
37
+ t.integer :rgt, :null => false, :index => true
38
+
39
+ # optional fields
40
+ t.integer :depth, :null => false
41
+ t.integer :children_count, :null => false
39
42
  end
40
43
  end
41
44
 
@@ -145,7 +145,18 @@ module CollectiveIdea #:nodoc:
145
145
  end
146
146
  end
147
147
 
148
- self.class.base_class.nested_set_scope options
148
+ self.class.base_class.unscoped.nested_set_scope options
149
+ end
150
+
151
+ # Separate an other `nested_set_scope` for unscoped model
152
+ # because normal query still need activerecord `default_scope`
153
+ # Only activerecord callbacks need unscoped model to handle the nested set records
154
+ # And class level `nested_set_scope` seems just for query `root` `child` .. etc
155
+ # I think we don't have to provide unscoped `nested_set_scope` in class level.
156
+ def nested_set_scope_without_default_scope(*args)
157
+ self.class.unscoped do
158
+ nested_set_scope(*args)
159
+ end
149
160
  end
150
161
 
151
162
  def to_text
@@ -171,7 +182,7 @@ module CollectiveIdea #:nodoc:
171
182
  end
172
183
 
173
184
  def right_most_node
174
- @right_most_node ||= self.class.base_class.unscoped.nested_set_scope(
185
+ @right_most_node ||= nested_set_scope(
175
186
  :order => "#{quoted_right_column_full_name} desc"
176
187
  ).first
177
188
  end
@@ -43,6 +43,7 @@ module CollectiveIdea #:nodoc:
43
43
  end
44
44
  elsif acts_as_nested_set_options[:dependent] == :restrict_with_exception
45
45
  raise ActiveRecord::DeleteRestrictionError.new(:children) unless leaf?
46
+ return true
46
47
  elsif acts_as_nested_set_options[:dependent] == :restrict_with_error
47
48
  unless leaf?
48
49
  record = self.class.human_attribute_name(:children).downcase
@@ -24,7 +24,7 @@ module CollectiveIdea #:nodoc:
24
24
 
25
25
  lock_nodes_between! a, d
26
26
 
27
- nested_set_scope.where(where_statement(a, d)).update_all(
27
+ nested_set_scope_without_default_scope.where(where_statement(a, d)).update_all(
28
28
  conditions(a, b, c, d)
29
29
  )
30
30
  end
@@ -33,7 +33,7 @@ module CollectiveIdea #:nodoc:
33
33
 
34
34
  delegate :left, :right, :left_column_name, :right_column_name,
35
35
  :quoted_left_column_name, :quoted_right_column_name,
36
- :quoted_parent_column_name, :parent_column_name, :nested_set_scope,
36
+ :quoted_parent_column_name, :parent_column_name, :nested_set_scope_without_default_scope,
37
37
  :primary_column_name, :quoted_primary_column_name, :primary_id,
38
38
  :to => :instance
39
39
 
@@ -121,7 +121,7 @@ module CollectiveIdea #:nodoc:
121
121
  when :child then right(target)
122
122
  when :left then left(target)
123
123
  when :right then right(target) + 1
124
- when :root then nested_set_scope.pluck(right_column_name).max + 1
124
+ when :root then nested_set_scope_without_default_scope.pluck(right_column_name).max + 1
125
125
  else raise ActiveRecord::ActiveRecordError, "Position should be :child, :left, :right or :root ('#{position}' received)."
126
126
  end
127
127
  end
@@ -29,7 +29,7 @@ module CollectiveIdea #:nodoc:
29
29
 
30
30
  def join_scope
31
31
  join_arel = arel_table.join(parent, Arel::Nodes::OuterJoin).on(parent[primary_column_name].eq(arel_table[parent_column_name]))
32
- self.scope = scope.joins(join_arel.join_sql)
32
+ self.scope = scope.joins(join_arel.join_sources)
33
33
  end
34
34
 
35
35
  def filter_scope
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '3.0.1' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '3.0.2' unless defined?(::AwesomeNestedSet::VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-30 00:00:00.000000000 Z
13
+ date: 2015-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -138,8 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.2.2
141
+ rubygems_version: 2.4.5
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: An awesome nested set implementation for Active Record
145
145
  test_files: []
146
+ has_rdoc: