Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you model Location in Core Data?

I want to make an Entity for Location with properties: latitude & longitude. Then, I want to set a relationship from User to Location, from Photo to Location, etc. Should I do it without creating an inverse relationship from Location to the others? Otherwise, how would I do it like that?

Thanks!

Matt

like image 840
ma11hew28 Avatar asked Nov 15 '22 07:11

ma11hew28


1 Answers

In most cases, you want to create an inverse relationship.

Inverse relationships make maintaing graph integrity easier and, more importantly, inverse relationships reflect the real-world relationships between the objects, events or conditions that the model simulates. The point of an object graph isn't merely the dumb storage of bits of data but also the active modeling of the relationships between different parts of that data. In Core Data, relationships themselves are active data.

In the real-world, photos are taken in locations and inversely some locations have photos taken in them. An inverse relationship would model that reality and give you the option of searching for photos based on their locations.

like image 122
TechZen Avatar answered Dec 19 '22 04:12

TechZen