Re: How to create subentity object inheriting from superentity object in core data
Re: How to create subentity object inheriting from superentity object in core data
- Subject: Re: How to create subentity object inheriting from superentity object in core data
- From: Leon Starr <email@hidden>
- Date: Thu, 17 Sep 2009 09:21:43 -0700
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 (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