- awakeFromFetch (Then Adding objects in a relationship)
- awakeFromFetch (Then Adding objects in a relationship)
- Subject: - awakeFromFetch (Then Adding objects in a relationship)
- From: email@hidden
- Date: Wed, 22 Feb 2006 18:49:12 -0800
Hi List,
I'm running into a slight problem implementing my entityA <->>
entityB type relationship.
In awake from fetch, I'm trying to see if there are any 'B' entities,
and if there are none, then I add at least one.
In awake from Insert, its fine, but I would like to check also when
awaking from fetch (a file open for example) but if
I add an object in a to-many relation inside of -awakeFromFetch, the
inverse of the relationship is not set correctly.
So opening the file the next time shows no entityB objects.....
Its a bit frustrating because everything works fine in
awakeFromInsert, but awakeFromFetch has some strange behavior.....
Here is my code:
- (void)awakeFromFetch
{
[super awakeFromFetch];
if ([[self valueForKey:@"blobs"] count] < 1)
[[self mutableSetValueForKey:@"blobs"] addObject:
[NSEntityDescription insertNewObjectForEntityForName:@"BLOB"
inManagedObjectContext:[self managedObjectContext]]];
}
- (void)awakeFromInsert
{
[super awakeFromInsert];
if ([[self valueForKey:@"blobs"] count] < 1)
[[self mutableSetValueForKey:@"blobs"] addObject:
[NSEntityDescription insertNewObjectForEntityForName:@"BLOB"
inManagedObjectContext:[self managedObjectContext]]];
}
And a simple example app is at:
http://homepage.mac.com/son_gohan/
Coradata_AwakeFromFetch_AddObjectIntoRelation.zip
To reproduce, create a record, delete the (automatically created)
"Blob" on the left column.
Save the file. Open the file. The app creates a default blob, now add
a sample image (included in the example) using the "image" button and
dragging it into the drawer.
Save the file. Open in textedit, and open in the app. Notice the blob
is gone, and the inverse was not set form the record object to the
blob......
Seems like a bug, but perhaps I'm just doing this in the wrong method?
Any pointers?
Thanks in advance.
Andre
email@hidden
_______________________________________________
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