Manual apply fix from 1.7_branch. Preserve database integrity for recurring todos when deleting project or context. Fixes #880. Fixes #895

This commit is contained in:
Reinier Balt 2010-04-04 18:20:07 +02:00
parent f67dd416d1
commit c3b3e3ea04
4 changed files with 8 additions and 0 deletions

View file

@ -163,6 +163,7 @@ class ProjectsController < ApplicationController
end end
def destroy def destroy
@project.recurring_todos.each {|rt| rt.remove_from_project!}
@project.destroy @project.destroy
@active_projects_count = current_user.projects.active.count @active_projects_count = current_user.projects.active.count
@hidden_projects_count = current_user.projects.hidden.count @hidden_projects_count = current_user.projects.hidden.count

View file

@ -1,6 +1,7 @@
class Context < ActiveRecord::Base class Context < ActiveRecord::Base
has_many :todos, :dependent => :delete_all, :include => :project, :order => "todos.completed_at DESC" has_many :todos, :dependent => :delete_all, :include => :project, :order => "todos.completed_at DESC"
has_many :recurring_todos, :dependent => :delete_all
belongs_to :user belongs_to :user
named_scope :active, :conditions => { :hide => false } named_scope :active, :conditions => { :hide => false }

View file

@ -27,6 +27,7 @@ class Project < ActiveRecord::Base
:order => "show_from" :order => "show_from"
has_many :notes, :dependent => :delete_all, :order => "created_at DESC" has_many :notes, :dependent => :delete_all, :order => "created_at DESC"
has_many :recurring_todos
belongs_to :default_context, :class_name => "Context", :foreign_key => "default_context_id" belongs_to :default_context, :class_name => "Context", :foreign_key => "default_context_id"
belongs_to :user belongs_to :user

View file

@ -639,6 +639,11 @@ class RecurringTodo < ActiveRecord::Base
starred? starred?
end end
def remove_from_project!
self.project = nil
self.save
end
def inc_occurences def inc_occurences
self.occurences_count += 1 self.occurences_count += 1
self.save self.save