I have a Class with an array of another class, much like your Order and OrderItem, but it doesn’t create the relational table for some strange reason. The FDWeek is set up in a viewcontroller and seven FDDays are created and added before the FDWeek get saved.
@IBAction func saveBtnTapped(sender: UIBarButtonItem) {
debugPrint("saveBtnTapped")
if newRecord {
debugPrint("create new week")
self.dismissKeyboard()
let newWeek = FDWeek()
newWeek.startDate = Utils.dateFromString(startDateTF.text!, format: "dd/MM/yyyy")
newWeek.weight = (weightTF.text! != "") ? Double(weightTF.text!)! : 0.0
newWeek.pTarget = (pGramTF.text! != "") ? Double(pGramTF.text!)! : 0.0
newWeek.fTarget = (fGramTF.text! != "") ? Double(fGramTF.text!)! : 0.0
newWeek.cTarget = (cGramTF.text! != "") ? Double(cGramTF.text!)! : 0.0
newWeek.suppPlan = suppPlanTF.text
for var index = 0; index < 7; index++ {
let date = Utils.addDaysToDate(newWeek.startDate, daysToAdd: Double(index))
let day = FDDay()
day.date = date
newWeek.days.append(day)
debugPrint("Day: \(Utils.stringFromDate(date, format: "dd/MM/yyyy"))")
}
debugPrint(newWeek.days)
self.dismissViewControllerAnimated(true, completion: nil)
newWeek.saveToServer()
} else {
debugPrint("update week")
}
}
I have attached the Classes as a .zip file. I can see the FDWeek class in Backendless, but the FDDay doesn’t get created. What am I doing wrong?
Archive.zip (2.3kB)