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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:40:20+00:00 2026-05-25T23:40:20+00:00

I have two entities in a Core Data Model like these: A <<—>> B

  • 0

I have two entities in a Core Data Model like these: A <<--->> B.
Entity B has an attribute name which is a string object and a relationship AObjects to A; instead, entity A has got a relationship BObjects to B.
Now I want to get a list of all BObjects connected with A entity and then, I want to show their names in a label.

Is this possible? I know CoreData doesn’t support many-to-many relationships…
Thanks!

  • 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-25T23:40:21+00:00Added an answer on May 25, 2026 at 11:40 pm

    I think you may not have fully described your situation, because of course Core Data absolutely does support many-to-many relationships. I suspect you may mean that an NSFetchedResultsController does not support many-to-many relationships? As far as I’ve been able to determine, that is correct. (Edit: It is possible to use an NSFetchedResultsController with many-to-many relationships… it is just not very obvious how to do it.)

    To do this without an NSFetchedResultsController, identify/fetch the A entity you are interested in, and then traverse the relationship you are interested in. So, if you already know that you are interested in a specific A object that I will call theAObject, with the class names A and B, you can just traverse the relationship using dot syntax and fast enumeration using something like the following:

    for (B *theBObject in theAObject.BObjects) {
        NSLog(@"theBObject.name: %@.", theBObject.name);
        // Run whatever code you want to here on theBObject.
        // This code will run once for each B Object associated with theAObject 
        // through the BObjects relationship.
    }
    

    Alternatively, you can set up a fetch request to get a set of AObjects you are interested in, and then traverse BOjects relationship for each of them. It does not make any difference that it is a many-to-many relationship… each AObjecct will return all B objects that are in its BObjects relationship.

    Later
    Now, you say you want to get all the names, and display it in a label. Let’s break that down for you:

    NSString *myLabel = null;
    // You may of course want to be declaring myLabel as a property and @synthesising
    // it, but for the sake of a complete example we'll declare it here which means 
    // it will only have local scope.
    
    for (B *theBObject in theAObject.BObjects) {
        myLabel = [myLabel stringByAppendingString:theBObject.name];    
        // Add a line break in the string after each B object name.
        myLabel = [myLabel stringByAppendingString:@"\n"];
    }
    
    // Do something with your myLabel string to set your desired label.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following core data model with two entities: entity item which holds
In my Core Data model I have two entities: List and Patient. List has
I have a core data model that has two entities, Bid and Result. I
I have a Core Data model with two entities: A and B. A has
In my core data model I have a Person entity that has a to
I have two Core Data entities: Parent and Child . Parent has to-many relationship
I have two core data entities, Articles and Favorite . Articles has To-Many relationship
i have two entities one called User and another called Membership which has a
Say you have a couple of Core Data entities .. Student and Exam. These
I have a core data model with an entity called clients that is made

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.