Application_Form/app/models/seminar_signup.rb

43 lines
1.1 KiB
Ruby

# encoding: utf-8
class SeminarSignup
include Mongoid::Document
include Mongoid::Timestamps
field :status
field :name # become Last Name for TICC
field :tel, type: String # become First Name for TICC
field :unit, localize: true
field :phone, type: String
field :fax, type: String
field :email, type: String
field :address, localize: true
field :password
field :note, localize: true
belongs_to :seminar_main
has_many :seminar_signup_values
has_many :seminar_signup_contributes
accepts_nested_attributes_for :seminar_signup_values, allow_destroy: true
accepts_nested_attributes_for :seminar_signup_contributes, allow_destroy: true
after_destroy do
seminar_main = self.seminar_main
seminar_reviews = seminar_main.seminar_reviews
id = self.id.to_s
seminar_reviews.each do |sr|
if sr.all_seminar_signup_ids.include?(id)
sr.seminar_signup_ids.delete(id)
sr.remove_seminar_signup_ids.delete(id)
sr.default_seminar_signup_ids.delete(id)
sr.save
end
end
if seminar_main.unassigned_seminar_signup_ids.delete(id)
seminar_main.save
end
end
end