From 3b72efcffd0079514713655a78e6d1c6dd7a274e Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 2 Nov 2011 02:33:20 +0400 Subject: [PATCH] Removing projects, platforms and repositorits when owner removed. Removing Relations joined with projects, platforms and repositories. --- app/models/platform.rb | 2 +- app/models/repository.rb | 4 ++-- app/models/user.rb | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index c31f45f46..75722b4d8 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -11,7 +11,7 @@ class Platform < ActiveRecord::Base has_many :repositories, :dependent => :destroy has_many :products, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation' + has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' diff --git a/app/models/repository.rb b/app/models/repository.rb index 7e0bec6f3..8495c534a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -5,9 +5,9 @@ class Repository < ActiveRecord::Base belongs_to :owner, :polymorphic => true has_many :projects, :through => :project_to_repositories #, :dependent => :destroy - has_many :project_to_repositories, :validate => true + has_many :project_to_repositories, :validate => true, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation' + has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' diff --git a/app/models/user.rb b/app/models/user.rb index 04056f709..45c2ea0cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,8 +12,10 @@ class User < ActiveRecord::Base has_many :targets, :as => :object, :class_name => 'Relation' - has_many :own_projects, :as => :owner, :class_name => 'Project' + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy + has_many :own_repositories, :as => :owner, :class_name => 'Repository', :dependent => :destroy has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true