Revision 442:753f1380d6bc vendor/plugins/awesome_nested_set/lib/.svn/text-base
| vendor/plugins/awesome_nested_set/lib/.svn/text-base/awesome_nested_set.rb.svn-base | ||
|---|---|---|
| 425 | 425 |
# the base ActiveRecord class, using the :scope declared in the acts_as_nested_set |
| 426 | 426 |
# declaration. |
| 427 | 427 |
def nested_set_scope |
| 428 |
options = {:order => quoted_left_column_name}
|
|
| 428 |
options = {:order => "#{self.class.table_name}.#{quoted_left_column_name}"}
|
|
| 429 | 429 |
scopes = Array(acts_as_nested_set_options[:scope]) |
| 430 | 430 |
options[:conditions] = scopes.inject({}) do |conditions,attr|
|
| 431 | 431 |
conditions.merge attr => self[attr] |
| ... | ... | |
| 444 | 444 |
# Prunes a branch off of the tree, shifting all of the elements on the right |
| 445 | 445 |
# back to the left so the counts still work. |
| 446 | 446 |
def prune_from_tree |
| 447 |
return if right.nil? || left.nil? || !self.class.exists?(id) |
|
| 447 |
return if right.nil? || left.nil? || leaf? || !self.class.exists?(id)
|
|
| 448 | 448 |
|
| 449 | 449 |
delete_method = acts_as_nested_set_options[:dependent] == :destroy ? |
| 450 | 450 |
:destroy_all : :delete_all |
| 451 | 451 |
|
| 452 |
# TODO: should destroy children (not descendants) when deleted_method is :destroy_all |
|
| 452 | 453 |
self.class.base_class.transaction do |
| 453 | 454 |
reload_nested_set |
| 454 | 455 |
nested_set_scope.send(delete_method, |
| ... | ... | |
| 466 | 467 |
["#{quoted_right_column_name} >= ?", right]
|
| 467 | 468 |
) |
| 468 | 469 |
end |
| 470 |
|
|
| 471 |
# Reload is needed because children may have updated their parent (self) during deletion. |
|
| 472 |
reload |
|
| 469 | 473 |
end |
| 470 | 474 |
|
| 471 | 475 |
# reload left, right, and parent |
Also available in: Unified diff