Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Ben Trumbull


On Sep 17, 2009, at 9:21 AM, Leon Starr wrote:

So, going back to my example, (and the part everyone disagrees  
with!) I still don't get it.  More importantly, my objc compiler  
doesn't get it!  In the model, Auto.license is properly inherited by  
the Sedan and Truck subentities.  No trouble at all with KVC  
interactions.  But if there is no @property/@dynamic for license in  
my Truck subclass, (only in the Auto subclasss) I cannot access  
thisTruck.license without getting a compiler error.  Which makes  
total sense to me since one NSManagedObject subclass (Truck) is not  
inheriting from another (Auto) in objc.  They each inherit from  
NSObject.  But I CAN do [thisTruck valueForKey:@"license"], which  
also makes perfect sense.


This violates the rule that a subentity must use an Objective-C class  
that is the same as its superentity, or a subclass of its  
superentity's Objective-C class.


If the Truck entity is a subentity of Auto, then it may reuse the  
AutoClass, or a TruckClass which must be a subclass of the AutoClass.


- Ben



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Leon Starr

NOW, I get it.  Thanks!  Problem solved.
(I knew you guys were seeing something I wasn't, so I'm glad I  
persisted - no pun* intended).


- Leon
*okay, intended

On Sep 17, 2009, at 9:49 , Quincey Morris wrote:


On Sep 17, 2009, at 09:21, Leon Starr wrote:

But if there is no @property/@dynamic for license in my Truck  
subclass, (only in the Auto subclasss) I cannot access  
thisTruck.license without getting a compiler error.  Which makes  
total sense to me since one NSManagedObject subclass (Truck) is not  
inheriting from another (Auto) in objc.  They each inherit from  
NSObject.


Nuh uh.

If the Objective-C classes are "Auto" and "Truck" (which are maybe  
the same names as your Core Data entities, although they don't  
*have* to match), then Auto *must* be a subclass of NSManagedObject:


@interface Auto : NSManagedObject ...

and Truck *must* be a subclass of Auto:

@interface Truck : Auto ...

That's what Ben meant when he said "class inheritance still applies  
normally".  The whole point of the exercise is to make the Objective- 
C inheritance chain *match* the entity inheritance chain.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/leon_starr%40modelint.com

This email sent to leon_st...@modelint.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Leon Starr
Not yet, anyway ;)  But, yes, I agree with you.  As it is, Core Data  
is purely an implementation tool.  And from what I can see so far, an  
excellent one.


- Leon

On Sep 17, 2009, at 9:38 , Kyle Sluder wrote:

You seem to have mistaken the modeler for a design tool. It's really  
an implementation tool. There is nothing you can do with Core Data  
that you can't do with the modeler. There is also nothing you can do  
with the modeler that you can't do with Core Data (well, besides  
leave attribute or relationships untyped, but that won't compile).


It is much more akin to a source code editor than it is a UML design  
tool.


--Kyle Sluder


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Quincey Morris

On Sep 17, 2009, at 09:21, Leon Starr wrote:

But if there is no @property/@dynamic for license in my Truck  
subclass, (only in the Auto subclasss) I cannot access  
thisTruck.license without getting a compiler error.  Which makes  
total sense to me since one NSManagedObject subclass (Truck) is not  
inheriting from another (Auto) in objc.  They each inherit from  
NSObject.


Nuh uh.

If the Objective-C classes are "Auto" and "Truck" (which are maybe the  
same names as your Core Data entities, although they don't *have* to  
match), then Auto *must* be a subclass of NSManagedObject:


@interface Auto : NSManagedObject ...

and Truck *must* be a subclass of Auto:

@interface Truck : Auto ...

That's what Ben meant when he said "class inheritance still applies  
normally".  The whole point of the exercise is to make the Objective-C  
inheritance chain *match* the entity inheritance chain.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Kyle Sluder
You seem to have mistaken the modeler for a design tool. It's really  
an implementation tool. There is nothing you can do with Core Data  
that you can't do with the modeler. There is also nothing you can do  
with the modeler that you can't do with Core Data (well, besides leave  
attribute or relationships untyped, but that won't compile).


It is much more akin to a source code editor than it is a UML design  
tool.


--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-17 Thread Leon Starr
Thanks, Ben.  I hear what you are saying about the draw tool, and,  
yes, I have played with it extensively.  In fact, I fancy myself an ER/ 
UML/Schema draw tool expert, and I'm afraid, the current Apple draw  
tool is a nice start, but has a long ways to go before I would  
consider using it on a serious project.   Consequently, I am  
determined to fully understand the programmatic interface with an eye  
towards adding some nice core data extension goodies once I get  
through my study phase.


I actually have implemented a data driven population engine that sucks  
up entity/prop/rel data, builds a model dictionary, and then iterates  
through it to construct the actual entity model.  And, yes, I am  
setting subentities as well as all the other entity, attr, and rel  
features.  Everything looks good in the mom console printout and xml  
store file.  So my trouble is really on the objc side, I believe.


So, going back to my example, (and the part everyone disagrees with!)  
I still don't get it.  More importantly, my objc compiler doesn't get  
it!  In the model, Auto.license is properly inherited by the Sedan and  
Truck subentities.  No trouble at all with KVC interactions.  But if  
there is no @property/@dynamic for license in my Truck subclass, (only  
in the Auto subclasss) I cannot access thisTruck.license without  
getting a compiler error.  Which makes total sense to me since one  
NSManagedObject subclass (Truck) is not inheriting from another (Auto)  
in objc.  They each inherit from NSObject.  But I CAN do [thisTruck  
valueForKey:@"license"], which also makes perfect sense.


Sorry for drawing out this thread, but I am intent on becoming a core  
data expert one of these days and do appreciate the newbie help!


- Leon


On Sep 16, 2009, at 22:20 , Ben Trumbull wrote:


Okay, my understanding, then, is that the inheritance is just in the
model - makes sense.  If you subclass NSManagedObjects for the parent
and child entities, you need to explicitly declare and synthesize
(dynamically) all common properties you want to access at lower  
levels

of the hierarchy (at least).


entity inheritance is just in the model.  class inheritance still  
applies normally.



Just to be clear, in the model I've got Entities: Auto, Sedan, Truck
and the parent (Auto) has a common property license.  Now when I  
get a

pointer to a Sedan or Truck I want the ability to access via
thisTruck.license or thisSedan.license.  In fact, if I end up with a
pointer (Auto *) thisAuto, I want thisAuto.license as well.

To get this to work, without KVC,  I need to declare @property/
@dynamic for license in Auto, Sedan and Truck.  (Can't just put it in
Auto and expect Sedan.license to work).  No big deal unless I have a
bunch of common properties in the parent entity.


No, Objective-C properties are inherited by subclasses.  If you use  
the modeling tools, your model will be created correctly, and your  
custom NSManagedObject subclasses will have the correct @interface  
definitions.  Even if you need to do all this programmatically, I'd  
recommend to play with the modeling tools more to see what things  
are supposed to look like.


- Ben



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Ben Trumbull

Okay, my understanding, then, is that the inheritance is just in the
model - makes sense.  If you subclass NSManagedObjects for the parent
and child entities, you need to explicitly declare and synthesize
(dynamically) all common properties you want to access at lower levels
of the hierarchy (at least).


entity inheritance is just in the model.  class inheritance still  
applies normally.



Just to be clear, in the model I've got Entities: Auto, Sedan, Truck
and the parent (Auto) has a common property license.  Now when I get a
pointer to a Sedan or Truck I want the ability to access via
thisTruck.license or thisSedan.license.  In fact, if I end up with a
pointer (Auto *) thisAuto, I want thisAuto.license as well.

To get this to work, without KVC,  I need to declare @property/
@dynamic for license in Auto, Sedan and Truck.  (Can't just put it in
Auto and expect Sedan.license to work).  No big deal unless I have a
bunch of common properties in the parent entity.


No, Objective-C properties are inherited by subclasses.  If you use  
the modeling tools, your model will be created correctly, and your  
custom NSManagedObject subclasses will have the correct @interface  
definitions.  Even if you need to do all this programmatically, I'd  
recommend to play with the modeling tools more to see what things are  
supposed to look like.


- Ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Ben Trumbull

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.  As you can see, I've created
the objects I need, but B doesn't know that A is it's superclass
object.  What to do?


Model the entity inheritance in the modeling tool is the easiest  
approach.  If you need to customize your model beyond that at runtime,  
you can make minor alterations programmatically by loading it and  
mutating it before creating your NSPersistentStoreCoordinator.  If you  
programmatically create a model, you'll need to add all the super  
entity's properties to each of the subentities.  The programmatic  
structure is much flatter than it would appear in the graphic Xcode  
tool.  There's no "calling super" in entity inheritance.


You'll need to set the objective-c class names for each entity.  The  
objective-c class must be either the same as the super entity's class  
or a subclass of that super entity's objective-c class.  You cannot  
create a random mapping of Objective-C classes to entity inheritance.


- Ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Quincey Morris

On Sep 16, 2009, at 18:38, Leon Starr wrote:

To get this to work, without KVC,  I need to declare @property/ 
@dynamic for license in Auto, Sedan and Truck.  (Can't just put it  
in Auto and expect Sedan.license to work).  No big deal unless I  
have a bunch of common properties in the parent entity.


No, you don't have to redeclare the properties in the subclasses.  
They're inherited normally. Remember that the entity inheritance chain  
and the Objective-C inheritance chain are orthogonal -- they coincide  
only to the extent you ensure they coincide.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Leon Starr
Okay, my understanding, then, is that the inheritance is just in the  
model - makes sense.  If you subclass NSManagedObjects for the parent  
and child entities, you need to explicitly declare and synthesize 
(dynamically) all common properties you want to access at lower levels  
of the hierarchy (at least).


Just to be clear, in the model I've got Entities: Auto, Sedan, Truck  
and the parent (Auto) has a common property license.  Now when I get a  
pointer to a Sedan or Truck I want the ability to access via  
thisTruck.license or thisSedan.license.  In fact, if I end up with a  
pointer (Auto *) thisAuto, I want thisAuto.license as well.


To get this to work, without KVC,  I need to declare @property/ 
@dynamic for license in Auto, Sedan and Truck.  (Can't just put it in  
Auto and expect Sedan.license to work).  No big deal unless I have a  
bunch of common properties in the parent entity.


Right?  (Sorry - no question, just looking for correction if I'm wrong!)

All that said, I can see that I would be better off using KVC and not  
subclassing at all unless I really need to for some reason.  Thanks  
again for the help guys!


- Leon

FROM : Quincey Morris
DATE : Thu Sep 17 00:49:25 2009

On Sep 16, 2009, at 14:55, Leon Starr wrote:

> Okay, guys, this helps a lot, still stuck, but getting closer!  Now
> I am getting an error with my revised code.  We are talking about
> two entities A and B where B where A is the parent of B.
> A has the property "name", and I would like to set that after
> creating an object for B.
>
> Here is the code:
>
> - (void)create_B: (NSString *)bName{
>NSEntityDescription *bEntity = [[model entitiesByName]
> objectForKey:@"B"];
>
>B *newB = [[OffDutyATC alloc] initWithEntity:bEntity
> insertIntoManagedObjectContext:context];
>newB.name = bName; // << ERROR request for member 'name' in
> something not a structure or union
> }
>
> Now I have defined an NSManagedObject class for both A and B with
> the "name" property/dynamic set for A.name.  But the B
> NSManagedObject class does not have any properties defined, so the
> error makes sense, but so much for normal inheritance!
>
> So what is the correct approach here?  Should I just use KVC to set
> the name property and not subclass NSManagedObject?  Or should I add
> property/dynamic statements to my B subentity to mirror A?  That
> seems kind of funky... Basically, what is the correct approach for
> setting the properties of a parent entity?


This part of your code looks fine. You're may have to show us your
@interface declarations for A and B (or at least the relevant parts).

The situation with properties is similar to the situation with
classes. Defining properties (attributes) in your managed object model
is *not* mirrored in your custom subclass(es) unless you do it yourself.

For example, if your model gives entity A a string attribute "name",
your custom A subclass also needs a @property NSString* name, if you
want the convenience of using the a.name syntax. (Or, yes, you can
reference the property via KVC.)

In the simplest case, Core Data provides you with a suitable
implementation of the @property accessors (-name and -setName), so all
you need is, in your @interface:

   @property NSString* name;

and in your @implementation:

   @dynamic name;

which means "use Core Data's handy-dandy implementation of the
accessors for 'name'".

If B is a subclass of A (by which I mean if entity B's custom subclass
is a subclass of entity A's custom subclass of NSManagedObject), then
B will inherit the "name" @property from A with no additional coding. 
___


Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Quincey Morris

On Sep 16, 2009, at 14:55, Leon Starr wrote:

Okay, guys, this helps a lot, still stuck, but getting closer!  Now  
I am getting an error with my revised code.  We are talking about  
two entities A and B where B where A is the parent of B.
A has the property "name", and I would like to set that after  
creating an object for B.


Here is the code:

- (void)create_B: (NSString *)bName{
   NSEntityDescription *bEntity = [[model entitiesByName]  
objectForKey:@"B"];


   B *newB = [[OffDutyATC alloc] initWithEntity:bEntity  
insertIntoManagedObjectContext:context];
   newB.name = bName; // << ERROR request for member 'name' in  
something not a structure or union

}

Now I have defined an NSManagedObject class for both A and B with  
the "name" property/dynamic set for A.name.  But the B  
NSManagedObject class does not have any properties defined, so the  
error makes sense, but so much for normal inheritance!


So what is the correct approach here?  Should I just use KVC to set  
the name property and not subclass NSManagedObject?  Or should I add  
property/dynamic statements to my B subentity to mirror A?  That  
seems kind of funky... Basically, what is the correct approach for  
setting the properties of a parent entity?


This part of your code looks fine. You're may have to show us your  
@interface declarations for A and B (or at least the relevant parts).


The situation with properties is similar to the situation with  
classes. Defining properties (attributes) in your managed object model  
is *not* mirrored in your custom subclass(es) unless you do it yourself.


For example, if your model gives entity A a string attribute "name",  
your custom A subclass also needs a @property NSString* name, if you  
want the convenience of using the a.name syntax. (Or, yes, you can  
reference the property via KVC.)


In the simplest case, Core Data provides you with a suitable  
implementation of the @property accessors (-name and -setName), so all  
you need is, in your @interface:


@property NSString* name;

and in your @implementation:

@dynamic name;

which means "use Core Data's handy-dandy implementation of the  
accessors for 'name'".


If B is a subclass of A (by which I mean if entity B's custom subclass  
is a subclass of entity A's custom subclass of NSManagedObject), then  
B will inherit the "name" @property from A with no additional coding.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Leon Starr
Okay, guys, this helps a lot, still stuck, but getting closer!  Now I  
am getting an error with my revised code.  We are talking about two  
entities A and B where B where A is the parent of B.
A has the property "name", and I would like to set that after creating  
an object for B.


Here is the code:

- (void)create_B: (NSString *)bName{
NSEntityDescription *bEntity = [[model entitiesByName]  
objectForKey:@"B"];


B *newB = [[OffDutyATC alloc] initWithEntity:bEntity  
insertIntoManagedObjectContext:context];
newB.name = bName; // << ERROR request for member 'name' in  
something not a structure or union

}

Now I have defined an NSManagedObject class for both A and B with the  
"name" property/dynamic set for A.name.  But the B NSManagedObject  
class does not have any properties defined, so the error makes sense,  
but so much for normal inheritance!


So what is the correct approach here?  Should I just use KVC to set  
the name property and not subclass NSManagedObject?  Or should I add  
property/dynamic statements to my B subentity to mirror A?  That seems  
kind of funky... Basically, what is the correct approach for setting  
the properties of a parent entity?


- Leon



From: Quincey Morris 
Date: September 16, 2009 11:22:46 AM PDT
To: cocoa-dev 
Subject: Re: How to create subentity object inheriting from  
superentity object in core data



On Sep 16, 2009, at 10:53, Leon Starr wrote:

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.  As you can see, I've  
created the objects I need, but B doesn't know that A is it's  
superclass object.  What to do?


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];
Now I have poured through all the related docs, and to my repeated  
consternation there are a million examples using stupid 1:1 or 1:M  
relationships but barely a whisper about programmatic entity  
inheritance.  Arggh!  Appreciate any help or pointers to whatever I  
missed in the docs.


I think a little terminology straightening might help you out.

Core Data doesn't have classes, it has entities. It doesn't have  
superclasses, it has parent entities. Entities and their parentage  
are defined in the Core Data model. If that's all you set up, all  
your Core Data objects will be of class NSManagedObject -- they'll  
all be the same Objective-C class, even though the entity parentage  
is correct and accounted for in Core Data's own data structures.


If you want you Core Data classes to have superclass ancestry to  
match their Core Data model parentage, you have to do it yourself.  
Define a custom NSManagedObject subclass corresponding to entity A,  
and define B and C subclasses of A (which are therefore also  
subclasses of NSManagedObject). In the entity descriptions for  
entities A, B and C, specify the corresponding class name.


Then, when you create a Core Data object the "normal" way  
(insertNewObjectForEntityForName:inManagedObjectContext:), Core Data  
will create the object with the correct Objective-C class, and  
you'll have the desired superclass ancestry.


Does that help?






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Quincey Morris

On Sep 16, 2009, at 10:53, Leon Starr wrote:

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.  As you can see, I've created  
the objects I need, but B doesn't know that A is it's superclass  
object.  What to do?


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];
Now I have poured through all the related docs, and to my repeated  
consternation there are a million examples using stupid 1:1 or 1:M  
relationships but barely a whisper about programmatic entity  
inheritance.  Arggh!  Appreciate any help or pointers to whatever I  
missed in the docs.


I think a little terminology straightening might help you out.

Core Data doesn't have classes, it has entities. It doesn't have  
superclasses, it has parent entities. Entities and their parentage are  
defined in the Core Data model. If that's all you set up, all your  
Core Data objects will be of class NSManagedObject -- they'll all be  
the same Objective-C class, even though the entity parentage is  
correct and accounted for in Core Data's own data structures.


If you want you Core Data classes to have superclass ancestry to match  
their Core Data model parentage, you have to do it yourself. Define a  
custom NSManagedObject subclass corresponding to entity A, and define  
B and C subclasses of A (which are therefore also subclasses of  
NSManagedObject). In the entity descriptions for entities A, B and C,  
specify the corresponding class name.


Then, when you create a Core Data object the "normal" way  
(insertNewObjectForEntityForName:inManagedObjectContext:), Core Data  
will create the object with the correct Objective-C class, and you'll  
have the desired superclass ancestry.


Does that help?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Leon Starr
Hmm.  Does that mean that I only need to create the subclass entity B  
as shown?


// 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];


So now that I have a newB (no pun intended) I can use that to access  
the superclass attributes just like normal inheritance, right?  I'm  
about to try it anyway, but if it would be helpful to know if this is  
the correct thinking.


On Sep 16, 2009, at 11:02 , Kyle Sluder wrote:

On Wed, Sep 16, 2009 at 10:53 AM, Leon Starr  
 wrote:
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?)


You don't need to tell it anything.  Core Data knows that every B  
isa A.


--Kyle Sluder



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to create subentity object inheriting from superentity object in core data

2009-09-16 Thread Kyle Sluder
On Wed, Sep 16, 2009 at 10:53 AM, Leon Starr  wrote:
> 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?)

You don't need to tell it anything.  Core Data knows that every B isa A.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com