when you save the house the array with members has to be empty. After the house is saved you can append the members like this ...
.task {
if let houses = await getHouses() {
do {
for house in houses {
modelContext.insert(house)
try modelContext.save()
// you need a var/let variable, that contains the members of this house somewhere separate from the house object
// append members to house after house is saved
house.members.append(contentsOf: members)
}
} catch {
print(error)
}
}
}