I have a todo list where each todo item can has_many tc_items.
class Todo < ActiveRecord::Base
acts_as_list
has_many :tc_items, :class_name => "TcItem", :dependent =>
true
has_one :where, :class_name => "TcItem", :conditions =>
"ckey=''where''"
end
My todo controller destroy action can either get the position column to
update correctly or delete the dependent tc_items correctly. But not
both - which is what I want.
1) If I want position column to update correctly (but dependents remain)
Todo.find(@params[''id'']).remove_from_list
Todo.delete(@params[''id''])
Destroying 3rd rec gives correct positions:-
1,2,3,4,5
1,2, 3,4
2) If I want to delete dependents correctly (but positions screwed up)
Todo.find(@params[''id'']).remove_from_list
Todo.destroy(@params[''id''])
Destroying 3rd rec:-
1,2,3,4,5
1,2, 3,3
3) Looking at the AR list.rb code I see
after_destroy :remove_from_list
which suggests (I am a Ruby Nooby) that all I should need to do is
destroy and then remove_from_list should be called automatically.
Todo.destroy(@params[''id''])
Destroying 3rd rec:-
1,2,3,4,5
1,2, 3,3
So yes, destroy does seem to be messing about with the position column
but it is screwing up.
4) If I just do remove_from_list :-
Todo.find(@params[''id'']).remove_from_list
Then I get (as expected)
Destroying 3rd rec:-
1,2,3,4,5
1,2,3,3,4
So I cant find a working combination of the above. Any help appreciated.
Peter