From 25c3ea9148b77b9388b4d73bf08af719baae9e4d Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 19 Aug 2010 11:25:04 +0200 Subject: [PATCH] fix #895 by clearing the repeat pattern from todos before the pattern is deleted --- app/controllers/contexts_controller.rb | 3 +++ app/models/recurring_todo.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 98ddc344..2b86660c 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -105,6 +105,9 @@ class ContextsController < ApplicationController # actions, you'll get a warning dialogue. If you choose to go ahead, any # actions in the context will also be deleted. def destroy + # make sure the deleted recurring patterns are removed from associated todos + @context.recurring_todos.each { |rt| rt.clear_todos_association } unless @context.recurring_todos.nil? + @context.destroy respond_to do |format| format.js { @down_count = current_user.contexts.size } diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index 57a2a8ee..9311a05a 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -636,6 +636,15 @@ class RecurringTodo < ActiveRecord::Base self.project = nil self.save end + + def clear_todos_association + unless todos.nil? + self.todos.each do |t| + t.recurring_todo = nil + t.save + end + end + end def inc_occurences self.occurences_count += 1