Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1924 (closed enhancement: untested)

Opened 4 years ago

Last modified 2 years ago

[PATCH] ActiveRecord::Acts::Tree acts_as_tree with :dependent options

Reported by: jeremy@jeremyhuffman.com Assigned to: David
Priority: normal Milestone: 1.2.4
Component: ActiveRecord Version: edge
Severity: normal Keywords: acts_as_tree unverified
Cc: demisone

Description

Currently, acts_as_tree creates a has_many collection specifying depdentent => true.

This is a bit unexpected, and undocumented. It results of course in the child records being automatically destroyed if the parent is destroyed.

I'd prefer to make this optional - defaulting to true, to maintain compatibility. This makes it possible to gracefully handle such scenarios in a before_destroy filter, for example.

The patch does this, and also further clarifies this behavior in the comment.

Attachments

.2 (0 bytes) - added by jeremy@jeremyhuffman.com on 08/08/05 22:55:04.
acts_as_tree_option_dependent.diff (1.5 kB) - added by jeremy@jeremyhuffman.com on 08/08/05 22:55:57.
allow_override_of_default_dependent_option_in_acts_as_tree.patch (1.6 kB) - added by bscofield on 01/28/07 21:10:30.
Patch updated to current edge (r6087)
acts_as_tree_with_dependent_options.patch (1.6 kB) - added by demisone on 05/20/07 10:52:00.
Against r6750

Change History

08/08/05 22:55:04 changed by jeremy@jeremyhuffman.com

  • attachment .2 added.

08/08/05 22:55:57 changed by jeremy@jeremyhuffman.com

  • attachment acts_as_tree_option_dependent.diff added.

06/21/06 00:34:50 changed by dark.panda@gmail.com

Any reason as to why this patch is still unapplied? I was bitten by this behaviour today and would prefer to have children set to null with ":dependent => :nullify" rather than having them silently (and unexpectedly) destroyed. It would be nice to be able to override this behaviour if possible.

01/28/07 21:10:30 changed by bscofield

  • attachment allow_override_of_default_dependent_option_in_acts_as_tree.patch added.

Patch updated to current edge (r6087)

01/28/07 21:15:38 changed by bscofield

  • keywords set to acts_as_tree.
  • version changed from 0.13.1 to edge.

I just uploaded a patch file to get this current for edge, r6087 - I know AAT will be extracted to a plugin at some point, but the current behavior is undocumented and at least sometimes unexpected (took me fifteen minutes to find out why my single-object-destroy test was deleting five objects).

02/25/07 19:24:06 changed by josh

  • keywords changed from acts_as_tree to acts_as_tree unverified.

05/20/07 10:49:40 changed by demisone

  • cc set to demisone.
  • summary changed from [PATCH] ActiveRecord acts_as_tree dependent optional to [PATCH] ActiveRecord::Acts::Tree acts_as_tree with :dependent options.
  • type changed from defect to enhancement.
  • milestone set to 1.2.4.

I will also supply a patch (it's pretty much the same with the two previous ones) for the current revision. (After all i'm not the only one who had trouble with the destroy... :) )

Please consider merging this patch. Otherwise when someone's using AAT and doesn't like the fact the :dependent is :destroy he has to re-write the implementation of AAT which results either in messing up with Rails code (bad bad bad!) or just throwing away the DRY principle...

05/20/07 10:52:00 changed by demisone

  • attachment acts_as_tree_with_dependent_options.patch added.

Against r6750

05/20/07 17:39:57 changed by bitsweat

  • status changed from new to closed.
  • resolution set to untested.

I agree. Needs tests.