summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-07-01 15:34:10 +0200
committerJames Lopez <james@jameslopez.es>2016-07-01 15:34:10 +0200
commitf29c30475e621dedae24791ae9b144b6bef2f80a (patch)
tree3850dee7b3703d2e0046015ec84ed700379b0124 /app
parentd6d0a35598c6fefd31dcc6b43bc2698792788faa (diff)
downloadgitlab-ce-f29c30475e621dedae24791ae9b144b6bef2f80a.tar.gz
use has_many relationship with events
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/eventable.rb15
-rw-r--r--app/models/issue.rb3
-rw-r--r--app/models/merge_request.rb3
-rw-r--r--app/models/milestone.rb2
-rw-r--r--app/models/note.rb2
5 files changed, 6 insertions, 19 deletions
diff --git a/app/models/concerns/eventable.rb b/app/models/concerns/eventable.rb
deleted file mode 100644
index aa23b350a06..00000000000
--- a/app/models/concerns/eventable.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module Eventable
- extend ActiveSupport::Concern
-
- def events
- Event.where(target_id: id, target_type: self.class.to_s)
- end
-
- def events=(events)
- events.each do |event|
- event.target_id = id
- event.data.deep_symbolize_keys! if event.data
- event.save!
- end
- end
-end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index ae177c041e7..60abd47409e 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -6,7 +6,6 @@ class Issue < ActiveRecord::Base
include Referable
include Sortable
include Taskable
- include Eventable
DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
@@ -20,6 +19,8 @@ class Issue < ActiveRecord::Base
belongs_to :project
belongs_to :moved_to, class_name: 'Issue'
+ has_many :events, as: :target, dependent: :destroy
+
validates :project, presence: true
scope :cared, ->(user) { where(assignee_id: user) }
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 326a0430eb4..5ebc8f0c99f 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -5,7 +5,6 @@ class MergeRequest < ActiveRecord::Base
include Sortable
include Taskable
include Importable
- include Eventable
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
@@ -13,6 +12,8 @@ class MergeRequest < ActiveRecord::Base
has_one :merge_request_diff, dependent: :destroy
+ has_many :events, as: :target, dependent: :destroy
+
serialize :merge_params, Hash
after_create :create_merge_request_diff, unless: :importing
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 2283376c8ac..2bd7f198030 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -11,13 +11,13 @@ class Milestone < ActiveRecord::Base
include Referable
include StripAttribute
include Milestoneish
- include Eventable
belongs_to :project
has_many :issues
has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues
has_many :merge_requests
has_many :participants, -> { distinct.reorder('users.name') }, through: :issues, source: :assignee
+ has_many :events, as: :target, dependent: :destroy
scope :active, -> { with_state(:active) }
scope :closed, -> { with_state(:closed) }
diff --git a/app/models/note.rb b/app/models/note.rb
index ed26fb2d88a..c2bb117eb03 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -5,7 +5,6 @@ class Note < ActiveRecord::Base
include Mentionable
include Awardable
include Importable
- include Eventable
# Attribute containing rendered and redacted Markdown as generated by
# Banzai::ObjectRenderer.
@@ -22,6 +21,7 @@ class Note < ActiveRecord::Base
belongs_to :updated_by, class_name: "User"
has_many :todos, dependent: :destroy
+ has_many :events, as: :target, dependent: :destroy
delegate :gfm_reference, :local_reference, to: :noteable
delegate :name, to: :project, prefix: true