summaryrefslogtreecommitdiffstats
path: root/app/models/committership.rb
diff options
context:
space:
mode:
authorMarius Mathiesen <marius.mathiesen@gmail.com>2009-06-02 13:21:07 +0200
committerMarius Mathiesen <marius.mathiesen@gmail.com>2009-06-02 13:21:18 +0200
commit1ad4ac049b787fac6eb4dc28aceffc5e52a504b3 (patch)
tree95e8a3b7a2288ddb3a56530a52ea90d0f11497a3 /app/models/committership.rb
parent4c134fcedf6d6abe4c6d5a3848b3d030f217c93e (diff)
downloadgitorious-mainline-outdated-1ad4ac049b787fac6eb4dc28aceffc5e52a504b3.zip
gitorious-mainline-outdated-1ad4ac049b787fac6eb4dc28aceffc5e52a504b3.tar.gz
gitorious-mainline-outdated-1ad4ac049b787fac6eb4dc28aceffc5e52a504b3.tar.bz2
In stead of destroying messages when their notifiables
are destroyed (which could lead to messages becoming invisible), we nullify the notifiable references. Since AR's dependent => nullify only nullifies the id, not the type, a before_destroy filter is introduced.
Diffstat (limited to 'app/models/committership.rb')
-rw-r--r--app/models/committership.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/committership.rb b/app/models/committership.rb
index a3d2907..b6f50b5 100644
--- a/app/models/committership.rb
+++ b/app/models/committership.rb
@@ -30,6 +30,8 @@ class Committership < ActiveRecord::Base
after_create :notify_repository_owners
after_create :add_new_committer_event
after_destroy :add_removed_committer_event
+ has_many :messages, :as => :notifiable
+ before_destroy :nullify_messages
named_scope :groups, :conditions => { :committer_type => "Group" }
named_scope :users, :conditions => { :committer_type => "User" }
@@ -84,4 +86,8 @@ class Committership < ActiveRecord::Base
repository.project.create_event(Action::REMOVE_COMMITTER, repository,
creator, committer.title)
end
+
+ def nullify_messages
+ messages.update_all({:notifiable_id => nil, :notifiable_type => nil})
+ end
end