Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 638929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:47:09+00:00 2026-05-13T20:47:09+00:00

Preface: I have two entities defined as a one-to-many relationship: A <<——-> B. B’s

  • 0

Preface:

I have two entities defined as a one-to-many relationship: A <<——-> B. B’s relationship to A is called myAs and is a to-many relationship with Nullify as the Delete Rule. The inverse relationship from A to B is a to-one relationship with Cascade as the Delete Rule.

I have implemented validateForDelete on the B class like so:

- (BOOL)validateForDelete:(NSError **)error {
    [super validateForDelete:error];
    BOOL validDelete = FALSE;

    if ([self.myAs count] == 0) {
        validDelete = TRUE;
    }

    return validDelete;
}

The purpose of this is to delete the object B only if there are no more A objects in a relationship with it (but always delete the B object if there are no longer any A objects in a relationship with it). This validateForDelete works as intended if I check for this validation manually before a save: on a B object deletion:

if ([b validateForDelete:NULL]) {
    //delete b object...
    [context save:&error];
    ...
}

The problem I am having is when a delete of a B object is being cascaded from an A object deletion. Users will not have access to B objects directly–they are created and deleted via A objects. Therefore, my rule that B objects are to be deleted when there are no more A object associated with it must be enforced from the A object–hence the cascade on delete.

The problem is that when I delete an A object, the validateForDelete is called on the B object because of the cascade. I am getting an resolved error: Unresolved error (null), (null) because I am not calling the validateForDelete manually.

Question(s):

How do I access the validateForDelete call from a cascading delete programmatically so that I can pass in an error variable and/or handle a validateForDelete result of FALSE?

If the above is not possible, how should I be handling this use case? Is there another more practical way of achieving this?

Thanks in advance.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:47:10+00:00Added an answer on May 13, 2026 at 8:47 pm

    First, your call to super is ignoring its response and it is not acting on the response from the super. That is generally a bad idea.

    Second, when you say NO to the validateForDelete it will throw an exception because the delete rule cannot be completed; in this case the cascade delete. In short, the validate method is not the correct place to be trying to handle this situation.

    To handle this situation you should be overriding the -prepareForDeletion method in the A class and have it peek at any Bs that fit that situation and delete them as appropriate. You will also want to change the delete rule to nullify instead of cascade. I would implement it as follows:

    - (void) prepareForDeletion
    {
      [super prepareForDeletion];
      if (![self myB]) return; //I don't have a B
      if ([[[self myB] myAs] count] > 1) return; //Has more relationships
      [[self managedObjectContext] deleteObject:[self myB]];
    }
    

    This will check to see if you have a B and if you do if that B has more than one relationship and if it doesn’t, add it to the queue for deletion. Otherwise it will allow Core Data to just nullify the relationship.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some preface: I'm a computer engineering student taking a first class in C after
Let me preface this by saying that perhaps there's a better way to do
Preface: So far I've used Python as a full scale programming language. Now I
(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011 ,
Preface: I am a complete bash noob. I want to write a simple script
Preface: I've got a System.Web.UI.WebControls.Table on my ASPx page that I define within the
Just as a preface, I'm not very knowledgeable on T-SQL syntax. I'd like to
First off, let me preface this question by saying that my professor is firmly
When trying to place a GRANT statement in an Oracle 11 stored procedure, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.