views:

165

answers:

1

I've got a generalization in my core data model with entities named A, B, C let's say where A is a super class with subentities B and C.

A is not abstract, so if I create an A NSManagedObject, I need to create and relate a single B or C subclass object. How do I make this happen? I can create the entities, but HOW do I tell the model that object B is a subclass of object A (or vice versa?)

Note: I did create the model programmatically and the subentities have been set properly for entity description "A".

Here's my sad attempt to move forward. Any ideas? Bonus points if you can direct me to a code sample that does the job. Thanks.

NSEntityDescription *aEntity = [[model entitiesByName] objectForKey:@"A"];
NSEntityDescription *bEntity = [[model entitiesByName] objectForKey:@"B"];

A *newA = [[A alloc] initWithEntity:aEntity insertIntoManagedObjectContext:context];
B *newB = [[B alloc] initWithEntity:ATC_Entity insertIntoManagedObjectContext:context];
A: 

Thanks to the cocoadev group for answering my question here and here: http://www.cocoabuilder.com/archive/message/cocoa/2009/9/16/245213

.../9/17/245264

(you'll have to fill in the 2nd link prefix) I am a new user and I just got: Oops! Your answer couldn't be submitted because:

* sorry, new users can only post a maximum of one hyperlink

Basically you just insert the subentity into your model and the superentity magically pops into existence. If you subclass your NSManagedObjects, you need to declare whatever properties you want to access.

Leon Starr