app/models/naf/application.rb in naf-2.0.4 vs app/models/naf/application.rb in naf-2.1.0
- old
+ new
@@ -5,20 +5,20 @@
:command,
:application_type_id,
:log_level,
:short_name,
:deleted,
- :application_schedule,
- :application_schedule_attributes
+ :application_schedules,
+ :application_schedules_attributes
#---------------------
# *** Associations ***
#+++++++++++++++++++++
belongs_to :application_type,
class_name: '::Naf::ApplicationType'
- has_one :application_schedule,
+ has_many :application_schedules,
class_name: '::Naf::ApplicationSchedule',
dependent: :destroy
has_many :historical_jobs,
class_name: '::Naf::HistoricalJob'
@@ -33,16 +33,15 @@
validates :short_name, uniqueness: true,
allow_blank: true,
allow_nil: true,
format: {
with: /^[a-zA-Z_][a-zA-Z0-9_]*$/,
- message: "letters should be first"
+ message: "short name consists of only letters/numbers/underscores, and it needs to start with a letter/underscore"
}
- validate :check_references_with_application_schedule_prerequisites
before_save :check_blank_values
- accepts_nested_attributes_for :application_schedule, allow_destroy: true
+ accepts_nested_attributes_for :application_schedules, allow_destroy: true
#--------------------
# *** Delegations ***
#++++++++++++++++++++
@@ -83,18 +82,8 @@
def check_blank_values
self.short_name = nil if self.short_name.blank?
self.log_level = nil if self.log_level.blank?
end
- def check_references_with_application_schedule_prerequisites
- if application_schedule.try(:marked_for_destruction?)
- prerequisites = Naf::ApplicationSchedulePrerequisite.
- where(prerequisite_application_schedule_id: application_schedule.id).all
- unless prerequisites.blank?
- errors.add(:base, "Cannot delete scheduler, because the following applications are referenced to it: " +
- "#{prerequisites.map{ |pre| pre.application_schedule.title }.join(', ') }")
- end
- end
- end
end
end