diff --git a/app/models/activity.rb b/app/models/activity.rb index 337b1782d0..c9aeba904d 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -131,8 +131,8 @@ class Activity < Ekylibre::Record::Base accepts_nested_attributes_for :distributions, reject_if: :all_blank, allow_destroy: true accepts_nested_attributes_for :inspection_point_natures, allow_destroy: true accepts_nested_attributes_for :inspection_calibration_scales, allow_destroy: true - accepts_nested_attributes_for :seasons, update_only: true, reject_if: -> (par) { par[:name].blank? } - accepts_nested_attributes_for :tactics, update_only: true, allow_destroy: true, reject_if: :all_blank + accepts_nested_attributes_for :seasons, allow_destroy: true, reject_if: -> (par) { par[:name].blank? } + accepts_nested_attributes_for :tactics, allow_destroy: true, reject_if: :all_blank accepts_nested_attributes_for :plant_density_abaci, allow_destroy: true, reject_if: :all_blank # protect(on: :update) do # productions.any? diff --git a/app/models/activity_season.rb b/app/models/activity_season.rb index a46b298546..c44e46c0e5 100644 --- a/app/models/activity_season.rb +++ b/app/models/activity_season.rb @@ -33,11 +33,13 @@ # class ActivitySeason < Ekylibre::Record::Base belongs_to :activity, class_name: 'Activity', inverse_of: :seasons - has_many :productions, class_name: 'ActivityProduction', inverse_of: :activity_season + has_many :productions, class_name: 'ActivityProduction', inverse_of: :season, foreign_key: :season_id # [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`. validates :activity, presence: true # ]VALIDATORS] - + protect(on: :destroy) do + productions.any? + end end diff --git a/app/models/activity_tactic.rb b/app/models/activity_tactic.rb index 4599556312..64dd089a34 100644 --- a/app/models/activity_tactic.rb +++ b/app/models/activity_tactic.rb @@ -54,5 +54,4 @@ class ActivityTactic < Ekylibre::Record::Base protect(on: :destroy) do productions.any? end - end diff --git a/app/views/backend/activities/_season_fields.html.haml b/app/views/backend/activities/_season_fields.html.haml index d17aaa869d..52e33f82f2 100644 --- a/app/views/backend/activities/_season_fields.html.haml +++ b/app/views/backend/activities/_season_fields.html.haml @@ -1,3 +1,3 @@ .nested-fields - = link_to_remove_nested_association(:seasons, f) + = link_to_remove_nested_association(:seasons, f) if f.object.destroyable? = f.input :name