2025-07-03 14:18:18 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Track < ApplicationRecord
|
2025-07-04 13:49:56 -04:00
|
|
|
include Calculateable
|
|
|
|
|
|
2025-07-03 14:18:18 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
has_many :points, dependent: :nullify
|
|
|
|
|
|
|
|
|
|
validates :start_at, :end_at, :original_path, presence: true
|
2025-07-04 14:55:05 -04:00
|
|
|
validates :distance, :avg_speed, :duration, numericality: { greater_than_or_equal_to: 0 }
|
2025-07-03 14:18:18 -04:00
|
|
|
|
2025-07-04 13:49:56 -04:00
|
|
|
after_update :recalculate_path_and_distance!, if: -> { points.exists? && (saved_change_to_start_at? || saved_change_to_end_at?) }
|
2025-07-03 14:18:18 -04:00
|
|
|
end
|