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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:59:35+00:00 2026-05-20T04:59:35+00:00

So i have two relationships between two entities in core data, titled number and

  • 0

So i have two relationships between two entities in core data, titled “number” and “info.” I give the user their number and when i do that i would like for them in return to give me their name so that I can tie it to their specific number. I cannot seem to get the code right to do this. So far the closest that i think i have gotten is this:

        for (UserNumber *pinNumbers in [entryView pinNumberArray]) {
            if ([numberString isEqualToString:pinNumbers.PIN]) {
                UserInfo *info = pinNumbers.info;   
                [info setName:nameField.text];  
            }
        }

where i loop through the number that they have entered and if i can find it inside the array that core data populates i would then like them to assign their name to this. Could anyone show me an example of how this might be done?

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-20T04:59:36+00:00Added an answer on May 20, 2026 at 4:59 am

    If your model is something like this:

    enter image description here

    such that there is a one-to-one bidirectional relationship between UserNumber and UserInfo, then it seems that you could probably have ‘number’ be an attribute of UserInfo and simplify your model. (Is it the case that ‘number’ is unique for each UserInfo?)

    But, going with your current model, assuming one-to-one relationship, something like this should work – provided that UserNumber has a ‘number’ attribute and to-one relationship called ‘info’ that points to a UserInfo.

    // Search for UserNumber that has NSString* pinCode as value for attribute PIN
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:@"UserNumber"
                             inManagedObjectContext:managedObjectContext]];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"PIN contains[cd] %@", pinCode];
    [fetchRequest setPredicate:predicate];
    
    NSError *error = nil;
    NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    [fetchRequest release];
    
    // UserNumber with matching PIN was found, so set name of associated UserInfo.
    if ( [items count] == 1 )
        {   
        UserNumber *userNumber = [items lastObject];
        UserInfo *userInfo = [userNumber info];
        [userInfo setName:nameField.text];
        }
    

    Note that items should have either zero or one element. If one, then that first element is the matching UserNumber. By traversing that UserNumber’s ‘info’ relationship, you will be able to get corresponding UserInfo – provided that you’ve properly created the link previously.

    Update

    In writing this code snippet, I realized that I don’t actually understand what you are trying to do ;-). Is this part of a registration process? If so, then you would need to deal with creation of UserInfo object and relationship between objects. Or is this part of logging in? Or part of editing user info? Anyway, hope this helps.

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

Sidebar

Related Questions

I have two Core Data entities ( Client and UserFile ) that I have
I have two entities Foo and Bar with a Many to Many relationship between
In my core data model I have a Person entity that has a to
Say you have a couple of Core Data entities .. Student and Exam. These
I have following two entities public class User { public int UserId { get;
What is the best way to change n-to-n relationships between two entities in JPA.
I've created two entities in core data model (Courier and Occupation in this example),
I have a many-to-many relationship between two entities - Media and MediaCollection. I want
I have a relationship between two tables, authors and styles. Every author is associated
I have a one to many relationship between two tables. The many table contains

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.