Skip navigation.
 
mlRe: Core Data - Cascading Not Working? (William Hunt) <SOLVED>
FROM : William Hunt
DATE : Thu Mar 13 06:06:56 2008

Problem Solved

As an update to my previous question... I'm an idiot.  I forgot to 
actually connect my two objects.  They were created, but not actually 
"connected."

--- Artificially Quoted.. ---

Hello, again!

Ok, my new problem deals with a very simple object graph that isn't
propagating deletes as I expect.  Here's the simplified setup:

Entity: Map
has a to-many relationship "rooms" to entity Room -- delete rule Cascade

Entity: Room
has a to-one relationship "map" to entity Map -- delete rule Nullify

These relationships are setup as inverses of each other.

My expectation is that if I delete a map entity, it will also delete
all rooms objects it references.

Now here's my test code:

- (void) testMapRoomCascade
{
    NSError *error = nil;

    [self createMapAndRoom1];
    NSArray *allRooms = [map allRooms: &error];
    int nRooms = [allRooms count];
    STAssertEquals( 1, nRooms, @"Map should have 1 room after
creating map and room." );

    NSArray *allMaps = [map allMaps: &error];
    [map delete: [allMaps objectAtIndex: 0]];

    int nMaps = [[map allMaps: &error] count];
    STAssertEquals( 0, nMaps, @"Map should have 0 maps after map
deletion." );

    allRooms = [map allRooms: &error];
    nRooms = [allRooms count];
    STAssertEquals( 0, nRooms, @"Map should have 0 rooms after map
deletion due to cascade delete rule." );  // <--- This is the error,
since nRooms is still 1!
}

--
Wil Hunt

"Life is the art of drawing sufficient conclusions from insufficient 
premises."
      -- Samuel Butler


On Mar 12, 2008, at 7:13 PM, <email_removed> wrote:

> Core Data - Cascading Not Working? (William Hunt)

Related mailsAuthorDate
No related mails found.