Dependent properties must be denormalized to use in a fetch request?
Dependent properties must be denormalized to use in a fetch request?
- Subject: Dependent properties must be denormalized to use in a fetch request?
- From: Scott Ellsworth <email@hidden>
- Date: Tue, 9 Aug 2005 13:53:19 -0700
Hi, all.
I have been trying to figure out how to use a dependent property -
gdp - in a fetch request in my core data project. This depends on
population and pcgdp, which are variables in my model. As <http://
www.cocoabuilder.com/archive/message/cocoa/2005/6/25/139993>
suggests, transient properties are not an option, because they are
not used in fetch requests.
It sure looks like the only path here is to add gdp to my model, and
then to make sure that the setters for population and pcdgp also
update the gdp primitive. That feels ugly, compared to:
[self setKeys:[NSArray arrayWithObjects:@"population",@"pcdgp",nil]
triggerChangeNotificationsForDependentKey:@"gdp"];
in my initialize method.
The current method is pretty easy:
- (NSNumber *)gdp{
float result= [[self valueForKey:@"population"] floatValue]*
[[self valueForKey:@"pcgdp"] floatValue];;
return [NSNumber numberWithFloat:result];
}
(The real method is more complicated, such that the CD parser barfs
if asked for the max. CD's sql store parser cannot handle any
complicated expression in a max, abs, min, etc.)
As best I read it, pretty though the above is, it is not going to
work with a fetch request.
If it is added to the model, then I would want to put in a validation
method that makes sure that setGDP is providing the correct value,
and both setValueForKey:@"population" and @"pcgdp" would need to call
setPrimitiveValueForKey:@"gdp" alongside the
setPrimitiveValueForKey:@"population" or @"pcdgp" they were already
doing.
Do I have this right?
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden