def check_full_tree
total_nodes = 0
transaction do
n = 1
roots.each do |r|
raise ActiveRecord::ActiveRecordError, "Gaps between roots in the tree containing record ##{r.id}" if r[left_col_name] != n
r.check_subtree
n = r[right_col_name] + 1
end
total_nodes = roots.inject(0) {|sum, r| sum + r.all_children_count + 1 }
unless base_set_class.count(:conditions => "#{scope_condition}") == total_nodes
raise ActiveRecord::ActiveRecordError, "Orphaned nodes or endless loops in the tree containing record ##{self.id}"
end
end
return total_nodes
end