From 0d46188002a4a2b8060657fa39ac60c59189db49 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Tue, 7 Mar 2023 12:30:05 +0800 Subject: [PATCH] Fix bug. --- app/models/seminar_main.rb | 11 ++++++----- app/views/admin/seminars/_form.html.erb | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index fa3392d..3332bd4 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -494,16 +494,17 @@ class SeminarMain approve_append = nil relations_fields.each do |k| belongs_to_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :belongs_to}.keys - has_many_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro == :has_many}.keys + has_many_class = clone_target.relations[k].class_name.constantize.relations.select{|k,v| v.macro.to_s.start_with?('has') }.keys if (belongs_to_class - tmp_singularize_relations_fields).count == 0 other_has_many_class = (has_many_class - unsort_relation_keys) if other_has_many_class.count == 0 tmp_relations_fields << k else + org_k = k.to_s result = other_has_many_class.map do |k| belongs_to_class = k.classify.constantize.relations.select{|kk,v| v.macro == :belongs_to}.keys - has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro == :has_many}.keys - if (belongs_to_class - tmp_singularize_relations_fields).count == 0 + has_many_class = k.classify.constantize.relations.select{|kk,v| v.macro.to_s.start_with?('has') }.keys + if (belongs_to_class - tmp_singularize_relations_fields - [org_k]).count == 0 true else fields_to_delete = fields_to_delete.concat(belongs_to_class) @@ -546,7 +547,7 @@ class SeminarMain no_dup_flag = false if clone_target.relations[f].macro == :belongs_to || clone_target.relations[f].macro == :has_one no_dup_flag = new_object.send(f).present? - elsif clone_target.relations[f].macro == :has_many + elsif clone_target.relations[f].macro == :has_many || clone_target.relations[f].macro == :has_and_belongs_to_many no_dup_flag = new_object.send(f).to_a.count != 0 elsif clone_target.relations[f].macro == :embeds_many #Fix localize fields if new_object.send(f).to_a.count != 0 @@ -597,7 +598,7 @@ class SeminarMain end end new_object.send("#{f}=",clone_relation) - elsif clone_target.relations[f].macro == :has_many + elsif clone_target.relations[f].macro == :has_many || clone_target.relations[f].macro == :has_and_belongs_to_many next if self.except_clone_relations.to_s.include?(f) clone_relations = [] need_clone_relations = clone_target.send(f).asc(:_id).to_a diff --git a/app/views/admin/seminars/_form.html.erb b/app/views/admin/seminars/_form.html.erb index e0c6ecb..2e03105 100644 --- a/app/views/admin/seminars/_form.html.erb +++ b/app/views/admin/seminars/_form.html.erb @@ -337,8 +337,8 @@ <%= t('seminar.disable') %> - - <%= check_box_tag("seminar_main[seminar_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %> + + <%= check_box_tag("seminar_main[seminar_email_sets_attributes][#{index1}][disabled]", true ,@email_set[index1].disabled) %> @@ -346,7 +346,7 @@ <%= t('seminar.email_title') %> - <%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'title','text_field') %> + <%= show_set_field(@email_set[index1],'seminar_email_sets_attributes',index1,'title','text_field') %> @@ -355,7 +355,7 @@
- <%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'content','text_area') %> + <%= show_set_field(@email_set[index1],'seminar_email_sets_attributes',index1,'content','text_area') %>