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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:26:14+00:00 2026-05-27T00:26:14+00:00

I have a one to many entity relationship between two entities: EntityP (Parent) <–>>

  • 0

I have a one to many entity relationship between two entities:

EntityP (Parent) <-->> EntityC (Child)

Attributes and Relationships:

EntityP.title
EntityP.dateTimeStamp
EntityP.PtoC (relationship)

EntityC.title
EntityC.dateTimeStamp
EntityC.CtoP (relationship) // Can be used to get "one" EntityP record

I use fetch results controller to show the results. Here’s my implementation of the fetch results controller:

#pragma mark -
#pragma mark Fetched results controller

- (NSFetchedResultsController *)fetchedResultsController {
     // Set up the fetched results controller if needed
     if (fetchedResultsController != nil) {
          return fetchedResultsController;
     }

     // Create the fetch request for the entity
     NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

     // Set Entity
     NSEntityDescription *entity = [NSEntityDescription entityForName:@"EntityC" inManagedObjectContext:self.managedObjectContext];
     [fetchRequest setEntity:entity];

     // Set Predicate
     // (Ignore, we want to get list of all EntityC records)

     // Set Sort Descriptors (sort on Parent - for section, and then on Child - for rows)
     NSSortDescriptor *sortDescriptorPDate = [[NSSortDescriptor alloc] initWithKey:@"CtoP.dateTimeStamp" ascending:YES];
     NSSortDescriptor *sortDescriptorDate = [[NSSortDescriptor alloc] initWithKey:@"dateTimeStamp" ascending:YES];
     NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptorPDate, sortDescriptorDate, nil];

     [fetchRequest setSortDescriptors:sortDescriptors];
     [fetchRequest setFetchBatchSize:20];

     // Create and initialize the fetch results controller
     NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"CtoP.title" cacheName:nil];
     aFetchedResultsController.delegate = self;
     self.fetchedResultsController = aFetchedResultsController;

     // Cleanup memory
     [aFetchedResultsController release];
     [fetchRequest release];
     [sortDescriptorPDate release];
     [sortDescriptorDate release];
     [sortDescriptors release];

     NSError *error = nil;
     if (![fetchedResultsController performFetch:&error]) {
          /*
           Replace this implementation with code to handle the error appropriately.

           abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
           */
          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
     }

     return fetchedResultsController;
}     

Now, for example, if i have following data in the persistence store:

EntityP.dateTimeStamp  EntityP.title    EntityC.dateTimeStamp   EntityC.title
Today                  B                Today                   d
Yesterday              A                Yesterday               a
Today                  B                Yesterday               c
Yesterday              A                Today                   b

Note: Yesterday and Today is in NSDate format.

Then i should get the sections and rows in following order (exactly):

A
 a
 b

B
 c
 d

But, the sort is not working like this. I’m getting the rows in correct order, but the sections are not ordered! I hope sortDescriptorPDate is doing his job. What am i missing? Thanking in anticipation.

  • 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-05-27T00:26:15+00:00Added an answer on May 27, 2026 at 12:26 am

    This seems to be working now! I’m not sure what changed! – Mustafa Sep 6 ’10 at 4:03

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

Sidebar

Related Questions

Suppose i have a one to many relationship between two model entities Entity One
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I've got two entities with a one-to-many relationship between them. The entity that holds
I have parent child relationship between two entities(Parent and Child). My Parent mapping is
I have a fairly simple Many to One relationship between two classes: @Entity public
I have two entities, Entity1 and Entity2, on a one to many relationship. On
I have a one to many relationship between two tables. The many table contains
I've mapped two entities using JPA (specifically Hibernate). Those entities have a one-to-many relationship
I have a many-to-many relationship between 2 entities in Entity Framework, like here .
I have a one-to-many relationship between Part and Params (a Part has many Params).

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.