Statuses in task - db field and forms
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
class Task < ApplicationRecord
|
||||
belongs_to :project
|
||||
belongs_to :status, class_name: 'TaskStatus'
|
||||
|
||||
validates :number, :title, presence: true
|
||||
validates :number, numericality: { greater_than: 0 }
|
||||
validate :associations_should_have_same_project
|
||||
|
||||
has_rich_text :description
|
||||
|
||||
@@ -25,4 +27,12 @@ class Task < ApplicationRecord
|
||||
project = Project.find_by!(code: project_code.downcase)
|
||||
find_by!(project:, number:)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def associations_should_have_same_project
|
||||
return if status&.project == project
|
||||
|
||||
errors.add(:status, "Doesn't belong in the same project")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,4 +7,6 @@ class TaskStatus < ApplicationRecord
|
||||
|
||||
validates :name, presence: true, uniqueness: { scope: :project }
|
||||
validates :category, presence: true
|
||||
|
||||
scope :default_order, -> { order(:category, :name) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user