When destroying a project, Redmine recursively destroys all related objects.
In this case however, it tries to first destroy the (project-local) time entry activities before it destroys the time entries using those activities. Since destroying an activity is only possible when there are no time entries using it, the project destroy may fail in this case.
I believe this may be solved by making sure that during a project destroy, Redmine first destroys the time entries and only then the activities.
I haven't yet fully tested it, but this issue might be solved with a patch like this where we move the declaration of the related time_entry_activities
below the declaration of the time_entries
:
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -30,8 +30,6 @@ class Project < ActiveRecord::Base
# Maximum length for project identifiers
IDENTIFIER_MAX_LENGTH = 100
- # Specific overridden Activities
- has_many :time_entry_activities, :dependent => :destroy
has_many :memberships, :class_name => 'Member', :inverse_of => :project
# Memberships of active users only
has_many :members,
@@ -44,6 +42,8 @@ class Project < ActiveRecord::Base
belongs_to :default_version, :class_name => 'Version'
belongs_to :default_assigned_to, :class_name => 'Principal'
has_many :time_entries, :dependent => :destroy
+ # Specific overridden Activities
+ has_many :time_entry_activities, :dependent => :destroy
has_many :queries, :dependent => :destroy
has_many :documents, :dependent => :destroy
has_many :news, lambda {includes(:author)}, :dependent => :destroy