From 36f609ec7ddbc2580312c949fc2a3a1e5528ea72 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 7 Feb 2012 01:47:39 +0600 Subject: [PATCH] [refs #143] fix destroy --- app/models/group.rb | 4 ++-- db/migrate/20120206194328_remove_orphan_platforms.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20120206194328_remove_orphan_platforms.rb diff --git a/app/models/group.rb b/app/models/group.rb index a720995ef..bc89373d4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -4,14 +4,14 @@ class Group < ActiveRecord::Base has_many :own_projects, :as => :owner, :class_name => 'Project' - has_many :relations, :as => :object, :dependent => :destroy has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true - has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true + has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true, :dependent => :destroy has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true + has_many :relations, :as => :object, :dependent => :destroy validates :name, :owner, :presence => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } diff --git a/db/migrate/20120206194328_remove_orphan_platforms.rb b/db/migrate/20120206194328_remove_orphan_platforms.rb new file mode 100644 index 000000000..aa922710a --- /dev/null +++ b/db/migrate/20120206194328_remove_orphan_platforms.rb @@ -0,0 +1,8 @@ +class RemoveOrphanPlatforms < ActiveRecord::Migration + def self.up + Platform.all.each {|x| x.destroy unless x.owner.present?} + end + + def self.down + end +end