module CollectiveIdea::Acts::NestedSet::Model::Rebuildable

Public Instance Methods

order_for_rebuild() click to toggle source
   # File lib/awesome_nested_set/model/rebuildable.rb
34 def order_for_rebuild
35   {
36     left_column_name => :asc,
37     right_column_name => :asc,
38     primary_key => :asc
39   }
40 end
rebuild!(validate_nodes = true) click to toggle source

Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree.

   # File lib/awesome_nested_set/model/rebuildable.rb
12 def rebuild!(validate_nodes = true)
13   # default_scope with order may break database queries so we do all operation without scope
14   unscoped do
15     Tree.new(self, validate_nodes).rebuild!
16   end
17 end
scope_for_rebuild() click to toggle source
   # File lib/awesome_nested_set/model/rebuildable.rb
19 def scope_for_rebuild
20   scope = proc {}
21 
22   if acts_as_nested_set_options[:scope]
23     scope = proc {|node|
24       scope_column_names.inject("") {|str, column_name|
25         column_value = node.send(column_name)
26         cond = column_value.nil? ? "IS NULL" : "= #{connection.quote(column_value)}"
27         str << "AND #{connection.quote_column_name(column_name)} #{cond} "
28       }
29     }
30   end
31   scope
32 end