I am creating a Travel Guide iPhone app. I created a city Entity in Core Data. It has name, image, and description attributes. Now I want to show restaurants and famous places according to selected cities in another view. Each city may have a number of restaurants and famous places. So I decided to create one other Entity, place. I am confused about the relationship between city and place. I want to make the city id as foreign key in place…what should I do?
I am creating a Travel Guide iPhone app. I created a city Entity in
Share
Core Data is not a relational database. Forget about foreign keys etc. You need to simply set a to-many relationship from the entity City to the entity Place. Also, you need to set the inverse relationship. At runtime, you will be updating one side only of the relationship: Core Data will automatically update the other one for you. This is just one of the benefits of using Core Data. But you need to start reading the documentation, in order to fully understand the difference w.r.t. a relational database. Core Data is an object graph management tool. It works with underlying XML, in memory and SQLite stores. The fact that your data may be backed-up by SQLite should not confuse you.
One more thing. You can not have an attribute called “description” in your entities. You can not have any attribute whose name is the same as one of the attributes of
NSObject. This collision will not work.