Module: Sunrise::NestedSet::Depth::ClassMethods
- Defined in:
- lib/sunrise/nested_set/depth.rb
Instance Method Summary collapse
- #depth? ⇒ Boolean
-
#update_depth ⇒ Object
Update cached_level attribute for all records tree.
Instance Method Details
#depth? ⇒ Boolean
18 19 20 |
# File 'lib/sunrise/nested_set/depth.rb', line 18 def depth? column_names.include?("depth") end |
#update_depth ⇒ Object
Update cached_level attribute for all records tree
8 9 10 11 12 13 14 15 16 |
# File 'lib/sunrise/nested_set/depth.rb', line 8 def update_depth roots.each do |node| connection.execute("UPDATE #{quoted_table_name} a SET a.depth = \ (SELECT count(*) - 1 FROM (SELECT * FROM #{quoted_table_name} WHERE #{scope_condition(node)}) AS b \ WHERE #{scope_condition(node, 'a')} AND \ (a.#{quoted_left_column_name} BETWEEN b.#{quoted_left_column_name} AND b.#{quoted_right_column_name})) WHERE #{scope_condition(node, 'a')}") end end |