lib/nested_set/base.rb in nested_set-1.6.1 vs lib/nested_set/base.rb in nested_set-1.6.2
- old
+ new
@@ -26,10 +26,11 @@
# Configuration options are:
#
# * +:parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id)
# * +:left_column+ - column name for left boundry data, default "lft"
# * +:right_column+ - column name for right boundry data, default "rgt"
+ # * +:depth_column+ - column name for level cache data, default "depth"
# * +:scope+ - restricts what is to be considered a list. Given a symbol, it'll attach "_id"
# (if it hasn't been already) and use that as the foreign key restriction. You
# can also pass an array to scope by multiple attributes.
# Example: <tt>acts_as_nested_set :scope => [:notable_id, :notable_type]</tt>
# * +:dependent+ - behavior for cascading destroy. If set to :destroy, all the
@@ -43,10 +44,11 @@
def acts_as_nested_set(options = {})
options = {
:parent_column => 'parent_id',
:left_column => 'lft',
:right_column => 'rgt',
+ :depth_column => 'depth',
:dependent => :delete_all, # or :destroy
}.merge(options)
if options[:scope].is_a?(Symbol) && options[:scope].to_s !~ /_id$/
options[:scope] = "#{options[:scope]}_id".intern
@@ -285,10 +287,14 @@
def scope_column_names
Array(acts_as_nested_set_options[:scope])
end
+ def depth_column_name
+ acts_as_nested_set_options[:depth_column]
+ end
+
def quoted_left_column_name
connection.quote_column_name(left_column_name)
end
def quoted_right_column_name
@@ -299,9 +305,13 @@
connection.quote_column_name(parent_column_name)
end
def quoted_scope_column_names
scope_column_names.collect {|column_name| connection.quote_column_name(column_name) }
+ end
+
+ def quoted_depth_column_name
+ connection.quote_column_name(depth_column_name)
end
end
# Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
#