Re: Dynamic data model in Core Data
Re: Dynamic data model in Core Data
- Subject: Re: Dynamic data model in Core Data
- From: "John R. Timmer" <email@hidden>
- Date: Wed, 10 May 2006 11:06:38 -0400
This can work, but it's not going to be easy or fluid for the user.
From the NSManagedObjectModel documentation:
"Managed object models are editable until they are used by an object
graph manager (a managed object context or a persistent store
coordinator). This allows you to create or modify them dynamically.
However, once a model is being used, it must not be changed. This is
enforced at runtime—when the object manager first fetches data using
a model, the whole of that model becomes uneditable. Any attempt to
mutate a model or any of its sub-objects after that point causes an
exception to be thrown. If you need to modify a model that is in use,
create a copy, modify the copy, and then discard the objects with the
old model."
So, basically, whenever a user modifies the schema, you'd need to
create a new managed object model, transfer all the data over, and
discard the old one. Plus, i don't see any method for writing out
your new managed object model to disk so that it's saved between
sessions (though it may exist). If you want to look into going this
route, read up on NSEntityDescription, which is how you'd create the
components of your schema.
One possible way around this is to simply have root objects that
correspond to the rows with a to-many relationship to objects that
contain an identifier, description, and data. Depending on your
needs, this may allow you to hold any arbitrary data, and simply
interpret the data based on the description (say, as a number or rich
text) as well as getting a column-like behavior based on the
identifier. Whether this would be more or less work than simply
going the SQLite route depends on what exactly you want to do.
JT
On May 9, 2006, at 8:08 PM, Andrew Carter wrote:
I'm working on a personal database application and am evaluating
using Core Data versus my own custom data model + SQLite. In
general, Core Data seems very close to what I want. However, the
very nature of my application will be allowing users to alter their
"schema" by adding and dropping "tables" and "columns".
Is this possible in core data? Is this a case that core data will
not be useful? I can see doing my own table/column/value core data
model objects but then I don't think I am getting much benefit from
core data. All the docs/tutorials I have seen talk about building
complete data models in the tool and freezing them. I am looking
to have some of the behaviors of the data modeling tool in my own
application.
____________________________________
Science writer, Ars Technica (among other things)
http://arstechnica.com/journals/science.ars
_______________________________________________
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