Lighthouse has a new layout.
Prefer the old one? Return to the old layout,
and switch back any time from the link at the top of each page.
This project is archived and is in readonly mode.
destroy fails on model with acts_as_list and has_many with :dependent => :destroy
#491
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.