On 12 Jul 2009, at 2:05 PM, Fritz Anderson wrote:

I have an entity, "Sale," that has a transient attribute "latestDate." It is marked optional/transient/indexed in the MOM; I've also tried it without setting optional. I set latestDate in awakeFromFetch and awakeFromInsert. I use [NSDate dateWithTimeIntervalSinceReferenceDate: 0] as a flag value.

At some point in my application, I want to retrieve all Sales that don't have that flag value. I do:

=====
NSFetchRequest *        fetch = [[NSFetchRequest alloc] init];
fetch.entity = [NSEntityDescription entityForName: @"Sale"
                           inManagedObjectContext: gMoc];
NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey: @"latestDate"
                                                          ascending: NO];
fetch.sortDescriptors = [NSArray arrayWithObject: sort];
[sort release]; 
NSPredicate * pred = [NSPredicate predicateWithFormat: @"latestDate != %@",
                                        [NSDate 
dateWithTimeIntervalSinceReferenceDate: 0]];
fetch.predicate = pred;
NSError *               error = nil;
NSArray *               retval = [gMoc executeFetchRequest: fetch error: 
&error];
=====

The execute... method raises
'NSInvalidArgumentException', reason: 'keypath latestDate not found in entity <NSSQLEntity Sale id=2>'

Only one Sale object is in the MOC. awakeFromInsert was called on it before this fetch is executed. I've searched my project for regular expressions that should catch most possible misspellings.

This is surely a rookie mistake, but I'm out of ideas. What am I doing wrong?

The predicate seems to be a red herring. Commenting out "fetch.predicate = pred" does not work around the bug, nor does changing the predicate to reference another attribute.

I've already mentioned that latestDate is set up in the MOM. In my code, it's

@property(nonatomic, retain) NSDate *   latestDate;
@dynamic latestDate;

Switching from self.latestDate = to [self setPrimitiveLatestDate:] in the awake... methods had no effect.

I've verified that there is only one Sale. It has not been saved.

        — F

_______________________________________________

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

Reply via email to