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 9231927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:11:28+00:00 2026-06-18T06:11:28+00:00

I have a Core Data model with three entities: Notification , Group and Customer

  • 0

I have a Core Data model with three entities: Notification, Group and Customer. These are the relationships between them:

  • A customer belongs to many groups and a group can have many customers.
  • A notification is sent (belongs) to a group and a group can receive (have) many notifications.

I would like to show all notifications in a UITableView grouped by customer. I have created a NSFetchedResultsController like this:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.fetchBatchSize = 10;
fetchRequest.predicate = nil;

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Notification"
                                          inManagedObjectContext:self.managedObjectContext];
fetchRequest.entity = entity;

// Default sort descriptors are built in a separate custom method
NSArray *sortDescriptors = [self getDefaultSortDescriptorsForEntity:entity];
fetchRequest.sortDescriptors = sortDescriptors;

return [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                           managedObjectContext:self.managedObjectContext
                    sectionNameKeyPath:@"group.customers.firstName"
                             cacheName:nil];

Assuming this is a valid way to retrieve all notifications grouped by customer (I’m not sure about that either) iOS is throwing the following exception:

@"Failed to fetch all Notification objects"
@"Reason: Invalid to many relationship in setPropertiesToFetch: (group.customers.firstName) (NSInvalidArgumentException)"

I have reviewed the relationships again and again to see if something is missing and everything seem to be correct. I can create and delete objects for all entities and links between them are correct as well.

My question is: Is it possible to traverse through several relationships in a sectionNameKeyPath value? How should many-to-many relationships be handled in this kind of scenario?

  • 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-18T06:11:29+00:00Added an answer on June 18, 2026 at 6:11 am

    Yes, you can do this. Just fetch the customers with the FRC and set the sectionNameKeyPath to nil.

    Sections
    The number of returned results is your number of sections. Populate the section headers with the customer data.

    Rows
    The number of rows in section would be customer.notifications.count. To populate the row, make sure the notifications are sorted in some way (say, by date) and display them accordingly with something like this:

    NSArray *orderedNotifications = 
      [customerForSection.notifications sortedArrayUsingDescriptors:
       @[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO]]];
    Notification *notificationToBeDisplayed = 
       [orderedNotifications objectAtIndex:indexPath.row];
    

    An alternative – recommended – solution is to change the data model. You could associate the notification with all customers directly. That would have the added advantage, that notifications remain associated with the correct customers even if group memberships change.

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

Sidebar

Related Questions

I have a simple has many relationship between 2 entities in Core Data: Team
I have a Core Data model which has three entities: A, B, and C.
Say I have a core data model with a few entities and, throughout the
In my Core Data model I have two entities: List and Patient. List has
I have this Core Data Model Hierarchy, with the respective relationships to each other:
I have a one-to-many relationship in my core data model. There can be many
Say you have a couple of Core Data entities .. Student and Exam. These
I have a Core Data model with two entities: A and B. A has
Basically I have three different Core Data entities ( A , B , C
I have a Core Data model with 2 entities: Game and ScoreTable. A Game

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.