views:

153

answers:

4

I'm working on my first app using Core Data and I need to assign a type (with an associated name attribute) to a couple of entities.

Below is my object model so far.

The room and item types will be updated from time to time over the network.

Is this the best way to implement this using Core Data? Thanks :)

Edit: To try to explain better: for example, rooms may be Bedrooms, Kitchens etc. Items can be Aircon, Security Camera etc. The only difference between the different room and item types is the name text. The list of valid name texts will be updated so I don't want to hard code it in the app. Also, the user can create multiple rooms and items of the same type, which is why they are numbered (roomNumber,itemNumber)

improved Core Data Model Image

A: 

I don't understand your separation of "Room" and "RoomType", or "Item" and "ItemType". Could you describe what you're implementing here?

NSResponder
+2  A: 

Nick, try and avoid the temptation of thinking of Core Data as a database. Design your model from the point of view looking at using the objects in your code.

i.e. your relationship properties are collections (or singluars) of the related thing.. you should rename the relationship JobLocation.JobLocationToRoom as just JobLocation.rooms

And yes, using Core Data will be quite straight forward, but it's hard to give you a definitive answer with such a vague question.

ohhorob
Thanks ohhorob - I was wondering about this.
NiKUMAN
BTW I've updated the relationship names in the model above.
NiKUMAN
A: 

Perhaps my question wasn't clear, but I found the answer in the Apple iPhoneCoreDataRecipes demo code

The relationship I wanted to model is similar to Recipe -> RecipeType.

NiKUMAN
A: 

In addition to the other answers, you don't need to model separate ID attributes. Core Data managed objects automatically have managed object IDs that are handled for you entirely behind-the-scenes by the framework.

Chris Hanson