BigW Consortium Gitlab

timelog.rb 491 Bytes
Newer Older
1 2
class Timelog < ActiveRecord::Base
  validates :time_spent, :user, presence: true
3
  validate :issuable_id_is_present
4

5 6
  belongs_to :issue
  belongs_to :merge_request
7
  belongs_to :user
8 9 10 11 12 13 14 15 16 17 18 19 20 21

  def issuable
    issue || merge_request
  end

  private

  def issuable_id_is_present
    if issue_id && merge_request_id
      errors.add(:base, 'Only Issue ID or Merge Request ID is required')
    elsif issuable.nil?
      errors.add(:base, 'Issue or Merge Request ID is required')
    end
  end
22
end