我正在尝试通过子标题列表进行保存,但使用相同的部门ID但不同的subheadDepartmentID。我该如何去做?
subHeadDepartment.department= department;
for(String thissubhead: ConstructedList){
SubHead subHead = SubHead.retrievebyName(thissubhead);
subHeadDepartment.subhead=subHead;
subHeadDepartment.save();
}
我这里的代码只是更新循环中的第一个subheadDepartment Id。虽然我想要的是为每个输入的子标题创建一个subheaddepartmentId,但所有子标题都在DB.Thanks中
答案 0 :(得分:0)
您需要为要创建的每个元素创建一个新的SubHeadDepartment实例:
for(String thissubhead: ConstructedList){
SubHead subHead = SubHead.retrievebyName(thissubhead);
SubHeadDepartment subHeadDepartment = new SubHeadDepartment();
subHeadDepartment.department = department;
subHeadDepartment.subhead = subHead;
subHeadDepartment.save();
}