Fogmeister Fogmeister - 1 year ago 56
Objective-C Question

Magical Record cascade delete (truncateAll) not deleting

I'm using Magical Record in my app.

I have a relationship...

Competition <-->> League

i.e. A
can have many
. A
can only have one

The delete rule from
Competition to League
is set to
. The inverse delete rule is set to

What I would expect to happen is if I delete a
then all
that belong to it are deleted also. (I have used this in previous apps successfully).

I am testing by doing...

  1. Download and insert all competitions and leagues.

  2. Log all Leagues with Competition names.

    NSArray *leagues = [League findAll];
    for (League *league in *leagues)
    NSLog(@"%@ - %@",,;

    e.g. Man UTD - Premier League

  3. run the following code...

    [Competition truncateAll];

  4. Log all Leagues with Competition names.

    e.g. Man UTD - (null)

I was expecting this to delete the
as well as the

Is my assumption correct in what it should do? Why isn't it doing it?

Answer Source

The relationship delete rules are applied when the managed object context is saved, or processPendingChanges is called.

As can be seen in the implementation, the MagicalRecord method MR_truncateAll calls deleteObject on all objects of an entity, but does not save the context.