Merge pull request 'Fix bug.' (#10) from 123/seminar:master into master

Reviewed-on: spen/seminar#10
This commit is contained in:
chiu 2023-03-18 08:26:57 +00:00
commit 81040a3413
1 changed files with 4 additions and 3 deletions

View File

@ -460,6 +460,7 @@ class SeminarMain
end
end
def clone_new_for_object(object,clone_target=nil,clone_mode=false)
@except_clone_relations ||= self.except_clone_relations
if clone_mode
new_object = object
clone_target = object.class.find(object.copy_id) rescue nil if clone_target.nil?
@ -467,7 +468,7 @@ class SeminarMain
clone_target = object if clone_target.nil?
new_object = object.dup
end
return if self.except_clone_relations.to_s.include?(new_object.class.to_s.underscore)
return if @except_clone_relations.to_s.include?(new_object.class.to_s.underscore)
@records_all["#{new_object.class.to_s.underscore.singularize}_ids"] = {} if @records_all["#{new_object.class.to_s.underscore.singularize}_ids"].nil?
begin
@records_all["#{new_object.class.to_s.underscore.singularize}_ids"][clone_target.id] = object.id
@ -585,7 +586,7 @@ class SeminarMain
new_object.send("#{f}_id=",(@records_all["#{f}_ids"][clone_target.send("#{f}_id")]))
end
elsif clone_target.relations[f].macro == :has_one
next if self.except_clone_relations.to_s.include?(f)
next if @except_clone_relations.to_s.include?(f)
need_clone_relation = clone_target.send(f)
clone_relation = new_object.send(f)
clone_relation, need_clone_relation = clone_new_for_object(need_clone_relation.dup, need_clone_relation, true) if clone_relation.nil?
@ -611,7 +612,7 @@ class SeminarMain
end
new_object.send("#{f}=",clone_relation)
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)
next if @except_clone_relations.to_s.include?(f)
clone_relations = []
need_clone_relations = clone_target.send(f).asc(:_id).to_a
file_flag = false