Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreDate: Inverse relationship returns NSCFNumber instead of entity



I'm stumped. In my model I have a Entry entity and a Reference entity. The Entry-Reference relationship is to-many, while the inverse is to-one. On the Entry side, the relationship's name is "references" and on the Reference side, the relationship's name is "entry". I've checked the setup a dozen times.

Both entities use their own NSManagedObject subclasses. I've checked this setup a number of times, and I'm certain I am following Core Data subclassing guidelines.

Because the Reference entity includes an "id" property which the entry uses to keep track of it, I've added a method to the Entry class which creates References:

- (Reference*) createReferenceForName:(NSString*)entityName {

Reference *newReference;
newReference = [NSEntityDescription insertNewObjectForEntityForName:entityName
inManagedObjectContext:[self managedObjectContext]];

[newReference setValue:[self nextReferenceIDAndIncrement] forKey:@"id"];

NSMutableSet *allReferences = [self mutableSetValueForKey:@"assets"];
[allReferences addObject:newReference];

return newReference;
}


The nextReferenceIDAndIncrement method looks like this:

- (NSNumber*) nextReferenceIDAndIncrement {

double nextIDdouble = [[self valueForKey:@"lastReferenceID"] doubleValue];
NSNumber *nextID = [NSNumber numberWithDouble:++nextIDdouble];
[self setValue:nextID forKey:@"lastReferenceID"];
return nextID;
}



For entityName I'm passing in the string "Reference." Everything seems to work. I can set properties on the Reference, display it in an NSTableView using bindings, etc.


However, there are parts of the code which access the Entry when the Reference has been supplied. Every time this code is called, the valueForKey method returns an NSCFNumber instead of the Entry with which the Reference is associated. The code is simple enough:

Entry *anEntry = [aReference valueForKey:@"entry"];

That anEntry variable is *always* a nNSCFNumber. Asking for any of attributes (title, icon, etc) returns the correct value. I'm completely stumped. The data model is correctly setup, I'm sure of it. The subclasses are proper, I'm sure as well. Why does valueForKey:@"entry" always return a number then when it is mapped to the Entry entity?

Recently, I did rename the Reference entity from "Resource," going through all the code and changing the necessary parts, as well as everything in the Nib files. I originally thought that could be related to the problem, but then I've completely re-written this part of the data model, even using different names for the entities and relationships. The problem remains the same. Short of trashing the data model file and rebuilding it from scratch, I don't know what to do.

Any direction would be appreciated.

-Phil

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.