[refs #143] fix destroy

This commit is contained in:
Alexander Machehin 2012-02-07 01:47:39 +06:00
parent 4f17968b3b
commit 36f609ec7d
2 changed files with 10 additions and 2 deletions

View File

@ -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_]+$/ }

View File

@ -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