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

  • Home
  • SEARCH
  • 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 8143611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:09:49+00:00 2026-06-06T13:09:49+00:00

From what I have been reading, for a relationship like department <->> employee ,

  • 0

From what I have been reading, for a relationship like department <->> employee, I can’t set a simple deletion rule that will cause department to be deleted if the last employee in a department is deleted. Instead, I have to code this rule.

I thought I might use key-value observing, with the didChangeValueForKey: method of the department entity. I want to centralize this delete action into one place, in a DRY way.

I wouldn’t expect that the department entity could delete itself, like this:

- (void) didChangeValueForKey:key {
    if (![key isEqualToString @"employee") return;
    if (self.employee == NULL)
        [self deleteAndSave];  // a category method
}

So I might post a notification, instead

- (void) didChangeValueForKey:key {
    if (![key isEqualToString @"employee") return;
    if (self.employee == NULL)
        [[NSNotificationCenter defaultCenter] postNotificationName:@"empDelete" object:self];
}

and then have the deletion take place in an object where I handle things like my managed object context.

Am I missing something that would make this easier?

  • 1 1 Answer
  • 0 Views
  • 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-06-06T13:09:50+00:00Added an answer on June 6, 2026 at 1:09 pm

    A good place for deletion rules is -(void)prepareForDeletion. You can implement any behavior you need, from the most simplistic to the most sophisticated.

    When deleting a department, you could per example move all the department’s employees to the parent department, if any. And when you delete an employee, you can check if the parent department still have employees and delete it if left empty. Your call.

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

Sidebar

Related Questions

I have been reading tutorials from several different places like http://css-tricks.com/scrollfollow-sidebar/ or http://jqueryfordesigners.com/fixed-floating-elements/ and
I have been reading that if you want to convert from JavaScript dates to
I have been reading that you HTML encode on the way back from the
I have been reading from the book The C Programming Language learning C, and
I previously have been reading NMEA data from a GPS via a serial port
Currently, I have been reading lists of data from a binary data file programmatically
What I have been able to grasp from reading the source and documentation from
I'm attempting to build a method call from strings that have been passed into
I have been set a project from school to design snake in VB.Net but
From what I have been reading a Linux distribution is little more than a

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.