Critter
Critter

Reputation: 462

Relational database -> CoreData

I have 3 tables.

Classes
---------------
classid
name
description

Sessions
---------------
sessionid
name
start
end

Schedule
---------------
scheduleid
name
start
end
classid
sessionid

I know how to set this all up in a relational database, but as far as setting them up as entities.. I am not sure which needs/should be the main object...

Upvotes: 1

Views: 537

Answers (2)

vicvicvic
vicvicvic

Reputation: 6244

What do you mean by "main object"? It's just a graph of entities and objects. In this case you should probably have one entity for each table (in singular: Class, Session, Schedule), with properties for the actual data and relationships for the foreign keys.

You can't manually specify the primary key, CoreData does that (it's an implementation detail).

So you'd probably have something like this:

Class

  • name (string)
  • description (string)
  • schedules (to-many relationship to Schedule)

Session

  • name (string)
  • start (date)
  • end (date)
  • schedules (to-many relationship to Schedule)

Schedule

  • name (string)
  • start (date)
  • end (date)
  • class ((reverse) relationship to Class)
  • session ((reverse) relatioinship to Session)

I can recommend Apple's own documentation on CoreData, especially the sections about the Data modelling tools in Xcode. It's possible to essentially draw your data models using Xcode and have the (optional) class declarations automatically generated for you.

Upvotes: 2

alexmage
alexmage

Reputation: 115

The main object would be your Schedule. You have a Schedule that has

-id
-name
-start
-end
-Class (or IList<Class>)
-Session (or Ilist<Session>)

Upvotes: 0

Related Questions