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) |
|---|
-
activerecord/lib/active_record/acts/tree.rb
old new 39 39 # * <tt>foreign_key</tt> - specifies the column name to use for tracking of the tree (default: parent_id) 40 40 # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet. 41 41 # * <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) 42 43 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 } 44 45 configuration.update(options) if options.is_a?(Hash) 45 46 46 47 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 => :destroy48 has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent] 48 49 49 50 class_eval <<-EOV 50 51 include ActiveRecord::Acts::Tree::InstanceMethods