Changeset 8

Show
Ignore:
Timestamp:
08/24/06 17:33:53 (2 years ago)
Author:
jcm
Message:

#4 && #5, before_create

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/init.rb

    r7 r8  
    11# better_nested_set 
    22# (c) 2005 Jean-Christophe Michel  
    3 # LGPL licence, see gnu.org 
     3# MIT licence 
    44# 
    55require 'better_nested_set' 
  • trunk/lib/better_nested_set.rb

    r7 r8  
    7171        #   (if that hasn't been already) and use that as the foreign key restriction. It's also possible  
    7272        #   to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. 
    73         #   Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt> 
     73        #   Example: <tt>acts_as_nested_set :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt> 
    7474        def acts_as_nested_set(options = {})           
    7575          if options[:scope].is_a?(Symbol)  
     
    137137        # on creation, set automatically lft and rgt to the end of the tree 
    138138        def before_create 
    139             maxright = self.class.count_by_sql("SELECT max(\"#{acts_as_nested_set_options[:right_column]}\") FROM "+self.class.table_name
    140             # adds the new node to the right of all existing nodes 
    141             self[acts_as_nested_set_options[:left_column]] = maxright+1 
    142             self[acts_as_nested_set_options[:right_column]] = maxright+2 
     139          maxright = self.class.maximum(acts_as_nested_set_options[:right_column], :conditions => acts_as_nested_set_options[:scope]
     140          # adds the new node to the right of all existing nodes 
     141          self[acts_as_nested_set_options[:left_column]] = maxright+1 
     142          self[acts_as_nested_set_options[:right_column]] = maxright+2 
    143143        end 
    144144