• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data, questions about two models in an application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data, questions about two models in an application


  • Subject: Re: Core Data, questions about two models in an application
  • From: rakel <email@hidden>
  • Date: Mon, 17 Jul 2006 18:52:01 +0200


17 jul 2006 kl. 17.41 skrev Jakob Olesen:


On 17/07/2006, at 14.43, rakel wrote:

I'm developing an application where data about persons can be managed. My data model contain two types of entities, meta data and person data. A meta data entity can be e.g. Variable. A person entity can be e.g. Value. There is a relation between the Variable and the Value entities, and also between the Value and the Person entities -- a person has a value for a variable, another person has another value for the same variable.

E.g. let there be a Variable called with title "Operating System". Then the person with name "Piglet" can have a Value for this Variable with the "valueData" attribute set to "Windows" and the person "Winnie the Pooh" can have a Value for the same Variable with "valueData" attribute set to "Mac OS X".

First of all, you are meta-modelling. You are making a model of a model. Are you sure that is what you need? You can't just have an operatingSystem property on a Person?



Yes, I'm meta-modelling, and yes that's what I need for this application! The reason I can't have an operatingSystem attribute on Person, is that the variables
1) are quite many (probably about a hundred)
2) might differ for different end users of the application
3) shall be possible to extend for the end user


One way is to start with a "Core Data Application" in XCode and have one data model with the entities Person, Value and Variable (this is how I currently do it).

I assume your data model looks like this:

Person <--->> Value <<---> Variable

That's correct.


Once again, this is complicated.

Yes, but beautiful :-)

Do you have all kinds of interesting attributes in the Variable entity?

Yes, among other things a Variable has a name, a description and optionally a ValueList, which limits the allowed values for Values
Variable <--->> ValueList


If you just have a name, get rid of the entity and simply put a variableName attribute in the Value entity.

Now to my question:

Another way could be to use a "Core Data Document Based Application" where each person is represented by one document. But since the Variables doesn't belong to any specific person, the Variable data cannot be part of the documents. Hence I would need two models, one model for the meta data and one model for the person data. Data for the "person data model" would be saved with each document. Data for the "meta data model" would be saved "somewhere else". Also, there must be a connection between the Value entity in the "person model" and the Variable entity in the "meta data model".

How do I do this? (Specifically, how do I maintain a relation between two entities in two different models?)

Check out the iClass example that comes with XCode. Basically, you save the URI of an object in a string attribute.

I will, thanks!


The example uses one stack for two stores. You probably want to use one stack for the metadata and one stack per document (as NSPersistentDocument does for you).


Since this means that you will be storing a variableURI string attribute in your Value entity, do consider if you could just call it variableName and get rid of the extra metadata store.

But really, documents with links to a global store is a bad idea. They are not really documents, you cannot move them to another computer (or user account for that matter).

Ok, that's interesting info, thanks! The reason I was thinking along these lines was to be able to put the data on a central location, and that more than one user should be able to work with the data (e.g. each user is responsible for his/her own Person documents) while minimizing the risk for corrupting the data (ok, I confess, I try to use Core Data as a database, which the documentation clearly states it's not... but Core Data is such a nice architecture so I would like to use it, at least for a prototype (which we all know will last forever -- the only things that lasts forever are diamonds and computer system prototypes ;-)!).


Thank you for your answer!

/Dan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Core Data, questions about two models in an application (From: rakel <email@hidden>)
 >Re: Core Data, questions about two models in an application (From: Jakob Olesen <email@hidden>)

  • Prev by Date: Re: KVO and the observeValueForKeyPath bottleneck
  • Next by Date: Newbie Q : using a framework
  • Previous by thread: Re: Core Data, questions about two models in an application
  • Next by thread: Multiple menu bars for multiple document types
  • Index(es):
    • Date
    • Thread