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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:29+00:00 2026-05-22T23:35:29+00:00

In my Core Data model, I have an entity Session and Exercise. Session has

  • 0

In my Core Data model, I have an entity Session and Exercise.

Session has a to many relationship to Exercise (there is a one-one inverse relationship as well).

In my fetch, I am trying to find all Session object that are related to the current Exercise.

I am using the following code which isn’t working.

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"exercise = %@", exercise.name]];
NSEntityDescription *sessionEntity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:sessionEntity];

NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"Fetch error: %@", error);
self.sessionArray = results;

Here is my data model:

enter image description here

  • 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-22T23:35:30+00:00Added an answer on May 22, 2026 at 11:35 pm

    First, from the screenshot it seems that your relationship attribute of the Session entity is called exercises not exercise.

    Also, it seems to me that it would work if you searched not the Session entity but the Exercise entity and then iterate through the resulting array to extract the sessions.

    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:"name == %@", exerciseName]];
    NSEntityDescription *exerciseEntity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:exerciseEntity];
    ...    
    NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    ...
    NSMutableArray *mutableSessionArray = [NSMutableArray array];
    for (Exercise *ex in results) {
        Session *session = [ex exercises];
        if (session) [mutableSessionArray addObject:session];
    }
    self.sessionArray = [NSArray arrayWithArray:mutableSessionArray];
    

    The relationship of the Exercise entity called exercises could be called session for clarity. I would recommend renaming it.

    BTW, you can also write = instead of ==, they are equivalent, as far as I know. In the Predicate Programming Guide section on Predicate Format String Syntax it says:

    =, ==
    The left-hand expression is equal to the right-hand expression.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity
I have a core data model which includes an entity with a to-many relationship.
I have a Core Data model setup like so: Blockbuster Entity To-Many relationship to
I have a one to many relationship in my core data model. I need
In my core data model I have a Person entity that has a to
in my Core Data model, I have an entity which has got a date
I have set up a Core Data model that includes an entity, Item with
I have an NSTreeController that manages an entity is a core data model and
In my Core Data managed object model, I have an entity Foo with a
In my Core Data model I have two entities: List and Patient. List has

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.