From bb44430b631eba1d33b218c97cb5d506073aeb08 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 21 Apr 2009 12:19:56 +0000 Subject: Ask user what to do with child pages when deleting a parent wiki page (#3202). 3 options are available: * move child pages as root pages * move child pages to another parent page * delete all descendants git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2676 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'vendor') diff --git a/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb b/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb index 6a6827ee6..54b4373ef 100644 --- a/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +++ b/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb @@ -40,11 +40,11 @@ module ActiveRecord # * order - makes it possible to sort the children according to this SQL snippet. # * counter_cache - keeps a count in a +children_count+ column if set to +true+ (default: +false+). def acts_as_tree(options = {}) - configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil } + configuration = { :foreign_key => "parent_id", :dependent => :destroy, :order => nil, :counter_cache => nil } configuration.update(options) if options.is_a?(Hash) belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache] - has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy + has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent] class_eval <<-EOV include ActiveRecord::Acts::Tree::InstanceMethods @@ -77,6 +77,13 @@ module ActiveRecord children + children.collect(&:children).flatten end + # Returns list of descendants and a reference to the current node. + # + # root.self_and_descendants # => [root, child1, subchild1, subchild2] + def self_and_descendants + [self] + descendants + end + # Returns the root node of the tree. def root node = self -- cgit v1.2.3