1
0

Allow binding goal saving w/o exposures and disallow destruction

This commit is contained in:
cryptogopher
2020-08-22 23:17:24 +02:00
parent 8f0e718b4a
commit cf0e14d87d
6 changed files with 51 additions and 33 deletions

View File

@@ -6,7 +6,7 @@ class Goal < ActiveRecord::Base
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
has_many :quantities, -> { order "lft" }, through: :target_exposures
validates :target_exposures, presence: true
validates :target_exposures, presence: true, unless: :is_binding?
validates :is_binding, uniqueness: {scope: :project_id}, if: :is_binding?
validates :name, presence: true, uniqueness: {scope: :project_id},
exclusion: {in: [I18n.t('targets.form.binding_goal')], unless: :is_binding?}
@@ -16,4 +16,7 @@ class Goal < ActiveRecord::Base
self.is_binding = false if self.is_binding.nil?
end
end
before_destroy prepend: true do
!is_binding?
end
end