Is it possible to override a property in an Entity subclass in CoreData?
Is it possible to override a property in an Entity subclass in CoreData?
- Subject: Is it possible to override a property in an Entity subclass in CoreData?
- From: "Barry Wark" <email@hidden>
- Date: Tue, 19 Feb 2008 15:15:21 -0800
I would like to emulate property type overloading in CoreData. The
model might look something like:
FooEntity (Abstract) {prop1:string, prop2 : UNKNOWN}
BarEntity (inherits FooEntity) {prop2 : int}
BazEntity (inherits FooEntity) {prop2 : double}
I would then like to be able to excute a fetch request on FooEntity
with predicate "prop1=='test' && prop2 == 10". The above object model
won't compile because CoreData won't let me have a prop2 in a subclass
of FooEntity. I tried removing FooEntity's prop2 property, but then
the fetch request fails because FooEntity doesn't have a prop2
property. So far, I've resorted to a model like
FooEntity (Abstract) {prop1:string, prop2Int : int, prop2Double : double}
BarEntity (inherits FooEntity) {}
BazEntity (inherits FooEntity) {}
and adding application logic to make sure that BarEntities use
prop2Int and BazEntities use prop2Double. A fetch request on FooEntity
then looks like "prop1 == 'test' && ((prop2Int ==10 &&
prop2Doulbe==nil) || (prop2Double == 10 && prop2Int == nil))".
My understanding is that subclasses in CoreData are all implemented in
one table so I'd think the original model could be implemented
(pseudo-)with database columns like prop2_FooEntity, prop2_BarEntity,
and prop2_BazEntity. The CoreData fetch could then translate the
original predicate ("prop1=='test' && prop2 == 10") into a query into
the appropriate column comparisons.
So, is there a cleaner, existing way to do this? Is this a feature
worth requesting for future CoreData?
Thanks,
Barry
_______________________________________________
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