summaryrefslogtreecommitdiffstats
path: root/app/models/issue_category.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-09-15 16:52:32 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-09-15 16:52:32 +0000
commitfa969504d4529ca9b2ceadf3c56f09b171c9170e (patch)
treeb0f3feff09ffafd1c5d8339b228eab4e18fedb3f /app/models/issue_category.rb
parent3c6ddc9cecc250b3853025ca8b10a964bed0ff97 (diff)
downloadredmine-fa969504d4529ca9b2ceadf3c56f09b171c9170e.tar.gz
redmine-fa969504d4529ca9b2ceadf3c56f09b171c9170e.zip
A category with assigned issue can now be deleted. 2 options are proposed:
* remove assignments (issues are set to 'no category') * reassign issues to another category (if at least an other category exists) If no issue is assigned to the category, it's deleted silently. git-svn-id: http://redmine.rubyforge.org/svn/trunk@733 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue_category.rb')
-rw-r--r--app/models/issue_category.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb
index fb2c099a1..1abcf4c32 100644
--- a/app/models/issue_category.rb
+++ b/app/models/issue_category.rb
@@ -16,15 +16,21 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueCategory < ActiveRecord::Base
- before_destroy :check_integrity
belongs_to :project
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
-
+ has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
+
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
-private
- def check_integrity
- raise "Can't delete category" if Issue.find(:first, :conditions => ["category_id=?", self.id])
+ alias :destroy_without_reassign :destroy
+
+ # Destroy the category
+ # If a category is specified, issues are reassigned to this category
+ def destroy(reassign_to = nil)
+ if reassign_to && reassign_to.is_a?(IssueCategory) && reassign_to.project == self.project
+ Issue.update_all("category_id = #{reassign_to.id}", "category_id = #{id}")
+ end
+ destroy_without_reassign
end
end