diff options
Diffstat (limited to 'app/models/timelog.rb')
-rw-r--r-- | app/models/timelog.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/app/models/timelog.rb b/app/models/timelog.rb index c1aa84cbbcd..bd543526685 100644 --- a/app/models/timelog.rb +++ b/app/models/timelog.rb @@ -3,20 +3,19 @@ class Timelog < ApplicationRecord include Importable + before_save :set_project + validates :time_spent, :user, presence: true validate :issuable_id_is_present, unless: :importing? belongs_to :issue, touch: true belongs_to :merge_request, touch: true + belongs_to :project belongs_to :user belongs_to :note - scope :for_issues_in_group, -> (group) do - joins(:issue).where( - 'EXISTS (?)', - Project.select(1).where(namespace: group.self_and_descendants) - .where('issues.project_id = projects.id') - ) + scope :in_group, -> (group) do + joins(:project).where(projects: { namespace: group.self_and_descendants }) end scope :between_times, -> (start_time, end_time) do @@ -37,6 +36,10 @@ class Timelog < ApplicationRecord end end + def set_project + self.project_id = issuable.project_id + end + # Rails5 defaults to :touch_later, overwrite for normal touch def belongs_to_touch_method :touch |