Group1
shouldn’t have all the properties of the PeopleProfile
it should only have the id
property of the person that’s saved, so it’s actually a list of UUID
. When you retrieve the data, you connect the data together (called joining) from the PeopleProfile
This is what’s called a foreign key relationship in relational databases.
Your entities should look like this:
-
PeopleProfile
: stores all the people-
id
asUUID
-
name
asString
-
-
Groups
: stores all the groups and what people are in that group-
GroupNumber
asInt
, this shouldn’t be an “id” because id usually means something that’s unique, which in your example it’s just denoting that someone is in group 1 -
PeopleProfileId
asUUID
, this is theUUID
of thePeopleProfile
-
When you fetch the data, you first fetch everyone from Groups
with a specific GroupNumber
, and then given that you have all the ids of the people. Next loop through those people and fetch all their information. (There might be a way to combine these, but I’m not sure what it is in CoreData). Haha I know what it would be writing normal SQL (which is used with relational databases)