This commit is contained in:
BOHUNG 2020-02-05 15:44:06 +08:00
parent 8ccddb921a
commit 61a8db592c
2 changed files with 5 additions and 4 deletions

View File

@ -21,9 +21,9 @@ class OlympiaSchoolDataFields
field :email , type: String , default: '' field :email , type: String , default: ''
field :enrollment , type: Fixnum , default: 0 field :enrollment , type: Fixnum , default: 0
field :approved , type: Boolean , default: true field :approved , type: Boolean , default: true
field :sign_up_setting_id , type: String , default: SignUpSetting.last.id.to_s field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s
after_destroy do |record| after_destroy do |record|
OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.last.id).destroy_all OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).destroy_all
end end
after_initialize do after_initialize do
if !self.new_record? if !self.new_record?
@ -36,7 +36,7 @@ class OlympiaSchoolDataFields
self.save! self.save!
end end
if self.enrollment == 0 #check enrollment student number if self.enrollment == 0 #check enrollment student number
self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.last.id).length self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).length
self.save! self.save!
end end
if self.enrollment_limited.nil? if self.enrollment_limited.nil?
@ -44,7 +44,7 @@ class OlympiaSchoolDataFields
self.save! self.save!
end end
if self.sign_up_setting_id.nil? if self.sign_up_setting_id.nil?
self.sign_up_setting_id = SignUpSetting.last.id.to_s self.sign_up_setting_id = SignUpSetting.where(:active=>true).last.id.to_s
self.save! self.save!
end end
sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil

View File

@ -39,6 +39,7 @@ class SignUpSetting
if self.active if self.active
SignUpSetting.where.not(:id=>self.id).each do |setting| SignUpSetting.where.not(:id=>self.id).each do |setting|
setting.active = false setting.active = false
setting.save!
end end
end end
end end