Great, now we have a working ShoppingList Model, but it won't compile yet since it depends on the Item Model as our ShoppingList has many items. To fix this, we need to create an Item Model similar to the ShoppingList Model. To do so, we need to follow these steps:
- Just like ShoppingList.swift, create a new file called Item.swift inside of the Models folder and make sure App target is checked otherwise you might get a compile error.
- Copy the following code for the Item.swift class:
import Vaporimport FluentProviderimport HTTPfinal class Item: Model { let storage = Storage() var name: String var isChecked: Bool = false var shoppingListId: Identifier var list: Parent<Item, ShoppingList> { return parent(id: shoppingListId) }