Here??™s an example that limits the set to only
those records with a related_id equal to zero:
class Comment < ActiveRecord::Base
acts_as_nested_set :scope => "related_id = 0"
end
What acts_as_nested_set Gives You
The acts_as_nested_set method provides nine methods. To help make the breakdown of each
of these methods easier to understand, let??™s define our comments table with default acts_as_
nested_set columns:
Comments table
id, integer (primary key, auto-incremented)
parent_id, integer (nulls ok)
lft, integer (nulls ok)
rgt, integer (nulls ok)
subject, varchar (nulls ok)
And recall our Comment model class:
class Comment < ActiveRecord::Base
acts_as_nested_set
end
And, so that we??™re all on the same page for the following examples, let??™s also assume our
database has at least the following records:
id, parent_id, left, rgt, subject
1,null,1,16,'root topic'
2,1,2,'node 1'
3,2,3,'node 1 child 1'
4,2,5,'node 1 child 2'
5,1,8,'node 2'
6,5,9,'node 2 child 1'
7,5,11,'node 2 child 2'
8,1,14,'node 3'
Finally, let??™s assume that we have a program that eventually executes the following line:
temp = Comment.
Pages:
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253