Changeset 8
- Timestamp:
- 08/24/06 17:33:53 (2 years ago)
- Files:
-
- trunk/init.rb (modified) (1 diff)
- trunk/lib/better_nested_set.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/init.rb
r7 r8 1 1 # better_nested_set 2 2 # (c) 2005 Jean-Christophe Michel 3 # LGPL licence, see gnu.org3 # MIT licence 4 4 # 5 5 require 'better_nested_set' trunk/lib/better_nested_set.rb
r7 r8 71 71 # (if that hasn't been already) and use that as the foreign key restriction. It's also possible 72 72 # 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> 74 74 def acts_as_nested_set(options = {}) 75 75 if options[:scope].is_a?(Symbol) … … 137 137 # on creation, set automatically lft and rgt to the end of the tree 138 138 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 nodes141 self[acts_as_nested_set_options[:left_column]] = maxright+1142 self[acts_as_nested_set_options[:right_column]] = maxright+2139 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 143 143 end 144 144
