Ticket #40: callback_fixes.patch

File callback_fixes.patch, 1.7 kB (added by rails, 1 year ago)
  • vendor/plugins/better_nested_set/lib/better_nested_set.rb

    old new  
    7070          include SymetrieCom::Acts::NestedSet::InstanceMethods 
    7171          extend SymetrieCom::Acts::NestedSet::ClassMethods 
    7272           
     73          before_create :add_new_node 
     74          before_destroy :delete_all_children 
     75           
    7376          # adds the helper for the class 
    7477#          ActionView::Base.send(:define_method, "#{Inflector.underscore(self.class)}_options_for_select") { special=nil 
    7578#              "#{acts_as_nested_set_options[:text_column]} || "#{self.class} id #{id}" 
     
    149152        end 
    150153         
    151154        # On creation, automatically add the new node to the right of all existing nodes in this tree. 
    152         def before_create # already protected by a transaction 
     155        def add_new_node # already protected by a transaction 
    153156          maxright = base_set_class.maximum(right_col_name, :conditions => scope_condition) || 0 
    154157          self[left_col_name] = maxright+1 
    155158          self[right_col_name] = maxright+2 
    156159        end 
    157160         
    158161        # On destruction, delete all children and shift the lft/rgt values back to the left so the counts still work. 
    159         def before_destroy # already protected by a transaction 
     162        def delete_all_children # already protected by a transaction 
    160163          return if self[right_col_name].nil? || self[left_col_name].nil? 
    161164          self.reload # in case a concurrent move has altered the indexes 
    162165          dif = self[right_col_name] - self[left_col_name] + 1