Re: subentity key undefined after merging models
Re: subentity key undefined after merging models
- Subject: Re: subentity key undefined after merging models
- From: "Eric Miller" <email@hidden>
- Date: Thu, 8 Mar 2007 11:55:08 -0700
How are you merging the models?
The code looks for .moms in the app and in the frameworks and loads them with
NSManagedObjectModel* model = [ [ NSManagedObjectModel alloc ]
initWithContentsOfURL:[ NSURL fileURLWithPath:path ] ];
Even if there is only one .mom in a bundle, it calls
[ NSManagedObjectModel modelByMergingModels:models ];
and returns that as the app's model and as each framework's model.
Given these models, it then calls
NSManagedObjectModel* result = [ NSManagedObjectModel
modelByMergingModels:[ NSArray arrayWithObjects: appModel,
baseGraphModel, rmrModel, nil ] ];
Where the models in the list are from the app and the frameworks.
baseGraphModel has my VizMirror entity and appModel has my DCamera
entity.
To hook up the superentity relationship:
NSDictionary* entities = [ result entitiesByName ];
// VizMirror should be parent of DCamera
NSEntityDescription* vizMirror = [ entities objectForKey:@"VizMirror" ];
NSEntityDescription* camera = [ entities objectForKey:@"DCamera" ];
NSArray* subentities = [ vizMirror subentities ];
NSMutableArray* newSubentities = [ NSMutableArray arrayWithArray:subentities ];
[ newSubentities addObject:camera ];
[ [ camera superentity ] setSubentities:[ NSArray array ] ]; //
disown from dummy
[ vizMirror setSubentities:newSubentities ];
I have to disown camera from its parent before setting it as a
subentity of VizMirror because in the app's .xcdatamodel it has a
dummy parent. This bit of weirdness isn't neccessary for the camera
but I'm planning on using something like that for plugins to hook
their entities into the app's model at the right spot. (Kind of a hack
... is there a better way?) At any rate, taking the dummy out and that
line doesn't help.
Calling [ vizMirror description ] at this point results in this:
(NSEntityDescription) name VizMirror, managedObjectClassName
VizMirror, isAbstract 0, superentity name (null), properties {
guid = (NSAttributeDescription), name guid, isOptional 0,
isTransient 0, entity VizMirror, validation predicates (), warnings
(), attributeType 700 , attributeValueClassName NSString, defaultValue
(null);
/* ... more properties ... */
}, subentities {
DCamera = (NSEntityDescription) name DCamera,
managedObjectClassName DCamera, isAbstract 0, superentity name
VizMirror, properties {
/* ... properties ... */
}, subentities {}, userInfo {};
And again, guid is the property for which the DCamera class is said
not to be kvc compliant.
Are there any runtime error messages?
No.
Thanks again ...
Eric Miller
On 3/8/07, mmalc crawford <email@hidden> wrote:
On Mar 8, 2007, at 9:22 AM, Eric Miller wrote:
> The app links to the framework and at run time the
> app merges the two .mom models and reunites the entities by calling
> VizMirror's setSubentities. Examining the entity descriptions confirms
> that the model seems to be in the right state.
>
How are you merging the models?
Are there any runtime error messages?
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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