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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:08:22+00:00 2026-05-24T09:08:22+00:00

Hi I have a evolving core data model setup as follows: lookup -> detail

  • 0

Hi I have a evolving core data model setup as follows:

lookup -> detail -> itemDetail

lookup is at the top level and for every 1 entity there can many in detail and for every entity in detail there can be 1 in itemDetail.

Prior to implementing itemDetail within my core data “engine” I have a method as follows:

`- (NSFetchedResultsController *)fetchedResultsController {

// if controller already created and the caller does not need a new one...

if (fetchedResultsController != nil && !needsNewFetchedResultsController) {

    return fetchedResultsController;
}


// we must flush the class cache first

[NSFetchedResultsController deleteCacheWithName:@"searches"];


// then set to nil to remove existing data

self.fetchedResultsController = nil;


// resetflag back to NO for future calls into this method

self.needsNewFetchedResultsController = NO;


// all the search results are in the "SearchDetail" table and categorised by the resource type

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"resource_type == %@ AND lookup.search_phrase == %@", self.resource, self.searchText];


// create the fetch request and set the predicate

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

fetchRequest.predicate = predicate;


// hook up to the required table  

NSEntityDescription *entity = [NSEntityDescription entityForName:@"SearchDetail" inManagedObjectContext:self.context];

[fetchRequest setEntity:entity];


// NSFetchedRequestController wants a sort, but we dont so just use type field to placate it ;-)

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"resource_type" ascending:NO];

[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                                                                                 managedObjectContext:self.context 
                                                                                                   sectionNameKeyPath:nil 
                                                                                                            cacheName:@"searches"];

self.fetchedResultsController = theFetchedResultsController;


self.fetchedResultsController.delegate = self;

[theFetchedResultsController release];

[sort release];

[fetchRequest release];

return self.fetchedResultsController;    

}
`

This allows me to retrieve data from detail for a search performed on lookup and all works well.

But now that I have included itemDetail I now need to grab data from itemDetail when a entry in detail is selected……but NSFetchedResulstController in my core data engine is setup up as above for a different query?

Do I need to have multiple methods for different NSFetchedResultsController or do I need to do some form of flag checking in existing one?

As my model grows I can see this growing into a beast of a problem so need to undertand it early rather than too late!

In hope….

  • 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-24T09:08:23+00:00Added an answer on May 24, 2026 at 9:08 am

    I am not sure I understand correctly your model. Assuming that your model contains the entities lookup, detail and itemDetail, the proper way to model this situations is as follows:

    lookup contains a to-many relationship to detail, call it details;
    detail contains a to-one relationship to itemDetail, call it itemDetail;

    Now, when you select a lookup object, you do not need any additional query (and therefore no additional NSFetchedResultsController) to retrieve the detail objects and from a detail object its corresponding itemDetail.

    You can simply do this:

    NSSet *details = yourSelectedLookupObject.details;
    
    // now browse the detail objects
    for(Detail *detailObject in details){
        // get the associated itemDetail
        ItemDetail *itemDetail = detailObject.itemDetail;
    
        // process itemDetail as needed ...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you ever seen any of there error messages? -- SQL Server 2000 Could
(Using Python 3.2, though I doubt it matters.) I have class Data , class
I have been evolving an automation and statistics generation program through a series of
Have just started using Google Chrome , and noticed in parts of our site,
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,

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.