This project is archived and is in readonly mode.

#491 ✓stale
mgomez

destroy fails on model with acts_as_list and has_many with :dependent => :destroy

Reported by mgomez | June 26th, 2008 @ 10:17 AM

I copy and paste from Rails Trac the following description, reported by donv :

I have an application that uses "has_many" with ":dependent => :destroy" to a model with "acts_as_list" with a ":null => false" constraint on the position column since I always want all rows in a list. This has worked fine with all version of Rails up to Rails 1.2.4. With Rails 1.2.5 it breaks with a NULL violation. It seems ActiveRecord tries to update the position column with a NULL value before it deletes the row. This seems completely unnecessary since the row will be immediately deleted anyway. It also breaks the NOT NULL constraint.

This unexpected behaviour still occurs in Rails 2.1

As danger explains:

The reason for this is that the acts_as_list plugin calls remove_from_list before a record is destroyed. That function readjusts the position of the other records and sets the position of the current record to nil.

My suggestion is that the method remove_from_list should set the position of the current record to the last in the list , instead of setting it to nil. Thus the removal would allow the correct positioning of the other items in the list, while the :null => false constrain remains possible.

Would someone be so kind to patch this?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages