Could help me with designing my data model, please? I'm developing a meal tracking app that counts meal calories by calculation all included ingredients.
My current data model: Meal and Ingredient are CoreData entities. Meal has a "to many" relationship to Ingredient, and Ingredient has "to one" Meal.
That works, but it's quite inconvenient. You have to retype all your ingredients for every meal even if you add them to other meals...
Meal keeps track of included Ingredients, and each Ingredient contains macros information and its size in Meal (basically, how many tomatoes you put in it).
My goal is to make "a catalog" of all user-added ingredients, so a user could search for them. But I'm struggling with the model design. I thought to change the Ingredient relationship to "to many", but where do I save the quantity of every ingredient in the particular meal?
Also, I thought about making "a proxy" Ingredient that has connections to Meal and Ingredient but also keeps size: Meal -> [List of proxies] -> Ingredient.
But I'm not sure if it's a good idea.
How would you do that?
CoreData Meal extension looks like this:
extension Meal {
...
@NSManaged public var name: String?
@NSManaged public var ingredients: NSSet?
}
And Ingredient:
extension Ingredient {
...
@NSManaged public var calories: Float
@NSManaged public var carbohydrates: Float
@NSManaged public var fats: Float
@NSManaged public var name: String?
@NSManaged public var psize: Float
@NSManaged public var protein: Float
@NSManaged public var meal: Meal?
}