1

In my app I have two entity in this way:

enter image description here

So, I've two questions:

1- when I delete a "First" entity I want to delete all entity "Characteristics" that belong to first. Do I set the delete rule "Cascade"?

2- If I delete a "characteristics" object from figure, with the method

- (void)removeCharacteristicsObject:(Characteristics *)value;

I want to delete also the characteristics identity, not only from figure, what's the way to do it?

thanks

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
  • Just as a side note. I'd rename your `Characteristics` entity to `Characteristic` (without the s). It will make working with them a whole lot easier. The relationship IS plural so the rel name is fine. Just change the entity name. – Fogmeister Apr 02 '14 at 10:09
  • 1
    Yeah I know, I create a fast example to create a clear situation, in my really project I use single names – cyclingIsBetter Apr 02 '14 at 10:17
  • OK, cool, just thought I'd mention it :D – Fogmeister Apr 02 '14 at 10:18

1 Answers1

2
  1. Correct. Set the delete rule for figure -> characteristic to Cascade. This will delete all the characteristics associated with a figure when you delete the figure.

  2. You don't even need to remove the characteristic. Just delete the characteristic and it will remove it from the figure. You could remove it and then delete it but easier just to delete it. Set the delete rule for characteristic -> figure to Nullify.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • for 2nd point: then with 'charateristics -> figure' setted with 'nullify' when I remove a charateristics form figure, the charateristics entity is also deleted? – cyclingIsBetter Apr 02 '14 at 10:05
  • No, the delete rules work the other way around. The nullify rule says "If the object is deleted, back pointers from the objects to which it is related are nullified." (Look up NSDeleteRule). This mean, if you delete the characteristic, then the pointer to it in the figure entity is nullified. If you remove the characteristic from the figure then nothing will happen. You'll be left with the characteristic still in the DB. – Fogmeister Apr 02 '14 at 10:07
  • 1
    ah ok, so the best thing is to delete directly the characteristics entity and in this way the entity is delete. And in this way in the figure don't appear the charatersistics associated; is it right? – cyclingIsBetter Apr 02 '14 at 10:15