diff options
author | Marius Mathiesen <marius.mathiesen@gmail.com> | 2009-06-02 13:21:07 +0200 |
---|---|---|
committer | Marius Mathiesen <marius.mathiesen@gmail.com> | 2009-06-02 13:21:18 +0200 |
commit | 1ad4ac049b787fac6eb4dc28aceffc5e52a504b3 (patch) | |
tree | 95e8a3b7a2288ddb3a56530a52ea90d0f11497a3 /app/models/merge_request.rb | |
parent | 4c134fcedf6d6abe4c6d5a3848b3d030f217c93e (diff) | |
download | gitorious-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/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 4462215..f524e16 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -25,9 +25,11 @@ class MergeRequest < ActiveRecord::Base belongs_to :source_repository, :class_name => 'Repository' belongs_to :target_repository, :class_name => 'Repository' has_many :events, :as => :target, :dependent => :destroy - has_many :messages, :as => :notifiable, :dependent => :destroy + has_many :messages, :as => :notifiable has_many :comments, :as => :target, :dependent => :destroy + before_destroy :nullify_messages + is_indexed :fields => ["proposal"], :include => [{ :association_name => "user", :field => "login", @@ -360,4 +362,9 @@ class MergeRequest < ActiveRecord::Base response = access_token.get("/") return Net::HTTPSuccess === response end + + def nullify_messages + messages.update_all({:notifiable_id => nil, :notifiable_type => nil}) + end + end |