bdc9322450
We can't properly use foreign keys on columns that are configured for polymorphic associations which has disadvantages related to data integrity and storage. Given we only use time tracking for Issues and Merge Requests we're moving to the usage of regular associations.
22 lines
491 B
Ruby
22 lines
491 B
Ruby
class Timelog < ActiveRecord::Base
|
|
validates :time_spent, :user, presence: true
|
|
validate :issuable_id_is_present
|
|
|
|
belongs_to :issue
|
|
belongs_to :merge_request
|
|
belongs_to :user
|
|
|
|
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
|
|
end
|