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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:27:55+00:00 2026-06-17T14:27:55+00:00

I have a model, where I have an entity called Category. This Category has

  • 0

I have a model, where I have an entity called “Category”. This Category has a one-to-many relationship called “Products”. How do I set up the fetch request to only get the Category entities WITHOUT the products?

  • 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-17T14:27:56+00:00Added an answer on June 17, 2026 at 2:27 pm

    If you query against Category, product elements are loaded as faults. This is the default behavior of CoreData.

    On the contrary if you use - (void)setRelationshipKeyPathsForPrefetching:(NSArray *)keys, you can load (pre-fetch) products when the request is executed.

    From Core Data App

    Faulting reduces the amount of memory your application consumes. A
    fault is a placeholder object that represents a managed object that
    has not yet been fully realized, or a collection object that
    represents a relationship
    :

    A managed object fault is an instance of the appropriate class, but
    its persistent variables are not yet initialized. A relationship fault
    is a subclass of the collection class that represents the
    relationship. Faulting allows Core Data to put boundaries on the
    object graph. Because a fault is not realized, a managed object fault
    consumes less memory, and managed objects related to a fault are not
    required to be represented in memory at all.

    and

    Pre-fetching is in effect a special case of
    batch-faulting, performed immediately after another fetch. The idea
    behind pre-fetching is the anticipation of future needs. When you
    fetch some objects, sometimes you know that soon after you will also
    need related objects which may be represented by faults. To avoid the
    inefficiency of individual faults firing, you can pre-fetch the
    objects at the destination
    .

    Edit

    If you need to count the number of products for a specific category, use - (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)error using a request like the following:

    NSFetchRequest* request = // set up a request for Products
    [request setPredicate:[NSPredicate predicateWithFormat:@"toCategory == %@", currentCategory]];
    // count for fetch request here...
    

    where toCategory is the inverse relationship from Products to Category and currentCategory is the category you have.

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

Sidebar

Related Questions

My model have 2 Entity (Category and News) with many to many relationship: (It
Say you have a one to one relationship in your entity model. The code
I am using entity model.i updated one view called SalesDetialView. In salesdetialview i have
Let's say I have an entity called EntityA . EntityA has a relationship to
I have a data model with an entity called Image. This will be used
I have a simple Coredata model with one entity called conversation and the other
I have a simple model entity, called entry with one field content and on
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have an entity model where the base class in an inheritance structure has
In my business model I have Entity class (IPoint interface ) that has 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.