Re: NSPersistentDocument and Multiple Managed Object Models?
Re: NSPersistentDocument and Multiple Managed Object Models?
- Subject: Re: NSPersistentDocument and Multiple Managed Object Models?
- From: Chris Hanson <email@hidden>
- Date: Wed, 29 Aug 2007 15:59:18 -0700
On Aug 29, 2007, at 1:18 PM, Michael Burns wrote:
Is it possible to have an NSPersistentDocument with two separate
managed object models?
Yes. You can create a merged model easily from any number of separate
models. See +[NSManagedObjectModel modelByMergingModels:]. However,
for what you actually need, read on...
I'm building a development environment for creating old school
adventure games with graphics and a simple scripting language. I
would like to have one model (the "development" model associated
with the documents persistent store) store all development-related
project data and a second one (a "runtime" model associated with a
store that is created when the user compiles/builds their project)
that consists of trimmed down information from the development model
(for instance, all of the scripts are parsed and compiled in to low-
level commands, etc.)
I know that's about as clear as mud, but hopefully someone can point
me in the right direction? Thanks!
Instead of using separate models for this purpose, you can use
separate configurations of a single model. A model can contain any
number of named configurations; each configuration can specify a
subset of entities in the model. Thus you can have Development and
Deployment configurations of your model. NSManagedObjectModel
supports configurations for exactly this purpose.
To use configurations, when asking a persistent store coordinator to
add a persistent store, just specify the name of the configuration to
use for that persistent store. The persistent store will then only
allow instances of entities in that configuration to be fetched and
saved. If a persistent store coordinator has multiple persistent
stores added using different configurations, it will even route
instances of those configurations' entities to the appropriate store,
i.e. it won't try to save an instance of an entity to a store that
doesn't support it.
Just remember that Core Data doesn't natively support cross-store
relationships, so you'll have to be careful not to design your model
such that you add one store with one half of a relationship and
another store with the other half. Unless you're prepared to do the
work of maintaining the relationship and its inverse yourself, you're
best off keeping each configuration self-contained or as complete
subsets and supersets.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden