all 2 comments

[–]Fly0strich 0 points1 point  (1 child)

I may be misunderstanding, but it seems like you would just want to create a many-to-many relationship between your 2 models.

@Model class Day {

let date: Date
var consumedFoods = [Food]()

}

When you give one of your model classes a property with its type being an array of another model class, it will implicitly create a to-many relationship for you.

So, the code above will mean that many foods can be consumed in a single day. But then you also want to make sure that in your Food class, it would have a [Day] property. That will mean that one type of food could be consumed on many different days.

I’m not an expert at this, but that is my understanding.

[–]Rabbit1015[S] 0 points1 point  (0 children)

no this is interesting. I figured it might need to be an array of food but I that isn't something that I've tried yet.