Fix bug. #9

Merged
chiu merged 1 commits from 123/seminar:master into master 2023-03-18 06:35:05 +00:00
1 changed files with 22 additions and 9 deletions
Showing only changes of commit 0788cfde1e - Show all commits

View File

@ -157,7 +157,7 @@ class SeminarMain
self.unassigned_seminar_signup_ids = [] self.unassigned_seminar_signup_ids = []
self.unassigned_mode_1_seminar_signup_ids = [] self.unassigned_mode_1_seminar_signup_ids = []
if self.copy_id.present? if self.copy_id.present?
clone_new(true) self.clone_new(true)
self.created_at = DateTime.now self.created_at = DateTime.now
self.updated_at = DateTime.now self.updated_at = DateTime.now
end end
@ -475,7 +475,14 @@ class SeminarMain
nil nil
end end
if !clone_target.nil? && !new_object.nil? if !clone_target.nil? && !new_object.nil?
if clone_mode
initialize_fields = []
if new_object.fields.keys.include?("uid")
new_object.generate_uid
end
else
initialize_fields = ["uid","created_at","updated_at"] initialize_fields = ["uid","created_at","updated_at"]
end
initialize_fields.each do |f| initialize_fields.each do |f|
new_object.send("#{f}=",nil) if new_object.fields.keys.include?(f) new_object.send("#{f}=",nil) if new_object.fields.keys.include?(f)
end end
@ -484,9 +491,8 @@ class SeminarMain
all_fields = all_fields - relations_fields.map{|k| "#{k}_id"} all_fields = all_fields - relations_fields.map{|k| "#{k}_id"}
all_fields = all_fields - relations_fields.map{|k| "#{k.singularize}_ids"} all_fields = all_fields - relations_fields.map{|k| "#{k.singularize}_ids"}
new_object_class_name = new_object.class.to_s.underscore new_object_class_name = new_object.class.to_s.underscore
relations_fields = clone_target.relations.except("impressions").keys
unsort_relation_keys = clone_target.relations.keys
unless @parent_level unless @parent_level
unsort_relation_keys = clone_target.relations.keys
fields_to_delete = [new_object_class_name] fields_to_delete = [new_object_class_name]
tmp_relations_fields = [new_object_class_name] tmp_relations_fields = [new_object_class_name]
while relations_fields.count > 0 while relations_fields.count > 0
@ -529,10 +535,16 @@ class SeminarMain
tmp_relations_fields << approve_append if approve_append.present? tmp_relations_fields << approve_append if approve_append.present?
approve_append = nil approve_append = nil
relations_fields = relations_fields - tmp_relations_fields relations_fields = relations_fields - tmp_relations_fields
relations_fields -= @relations_fields if @relations_fields
end end
relations_fields = tmp_relations_fields relations_fields = tmp_relations_fields
fields_to_delete.each{|f| relations_fields.delete(f)} fields_to_delete.each{|f| relations_fields.delete(f)}
end
if @parent_level
relations_fields -= @relations_fields
else
@clone_mode = clone_mode @clone_mode = clone_mode
@relations_fields = relations_fields
end end
@parent_level = true @parent_level = true
if clone_mode if clone_mode
@ -576,7 +588,7 @@ class SeminarMain
next if self.except_clone_relations.to_s.include?(f) next if self.except_clone_relations.to_s.include?(f)
need_clone_relation = clone_target.send(f) need_clone_relation = clone_target.send(f)
clone_relation = new_object.send(f) clone_relation = new_object.send(f)
clone_relation = need_clone_relation.dup if clone_relation.nil? clone_relation, need_clone_relation = clone_new_for_object(need_clone_relation.dup, need_clone_relation, true) if clone_relation.nil?
initialize_fields.each do |f| initialize_fields.each do |f|
clone_relation.send("#{f}=",nil) if clone_relation.fields.keys.include?(f) clone_relation.send("#{f}=",nil) if clone_relation.fields.keys.include?(f)
end end
@ -630,11 +642,12 @@ class SeminarMain
end end
if !no_dup_flag || (no_dup_flag && file_flag) if !no_dup_flag || (no_dup_flag && file_flag)
new_object_relations = new_object.send(f).to_a new_object_relations = new_object.send(f).to_a
if new_object_relations.count != 0 new_object_relations_count = new_object_relations.count
if clone_relations.count > new_object_relations.count if new_object_relations_count != 0
clone_relations = clone_relations[0...new_object_relations.count] if clone_relations.count > new_object_relations_count
clone_relations = clone_relations[0...new_object_relations_count]
else else
clone_relations = clone_relations.concat(new_object.send(f)[clone_relations.count...new_object_relations.count]) clone_relations = clone_relations.concat(new_object.send(f)[clone_relations.count...new_object_relations_count])
end end
new_object.send("#{f}=",clone_relations) new_object.send("#{f}=",clone_relations)
else else