Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1924: allow_override_of_default_dependent_option_in_acts_as_tree.patch

File allow_override_of_default_dependent_option_in_acts_as_tree.patch, 1.6 kB (added by bscofield, 2 years ago)

Patch updated to current edge (r6087)

  • activerecord/lib/active_record/acts/tree.rb

    old new  
    3939        # * <tt>foreign_key</tt> - specifies the column name to use for tracking of the tree (default: parent_id) 
    4040        # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet. 
    4141        # * <tt>counter_cache</tt> - keeps a count in a children_count column if set to true (default: false). 
     42        # * <tt>dependent</tt> - makes it possible to set the action to take on the children of a deleted node; takes the same options as has_many :dependent (default: :destroy) 
    4243        def acts_as_tree(options = {}) 
    43           configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil
     44          configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil, :dependent => :destroy
    4445          configuration.update(options) if options.is_a?(Hash) 
    4546 
    4647          belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache] 
    47           has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy 
     48          has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent] 
    4849 
    4950          class_eval <<-EOV 
    5051            include ActiveRecord::Acts::Tree::InstanceMethods