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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:18+00:00 2026-06-15T22:51:18+00:00

I have three entities: Session, User and Test. A session has 0-many users and

  • 0

I have three entities: Session, User and Test. A session has 0-many users and a user can perform 0-6 tests. (I say 0 but in the real application always at least 1 is required, at least 1 user for a session and at least 1 test for a user. But I say 0 to express an empty start.) All entities have their own specific data attributes too. A user has a name, A session has a name, a test has six values to be filled in by the user, and so on. But my issue is with the relationships.

  1. How do I set multiple users and have them added to one session (same goes for multiple tests for one user).

  2. How do I show the content in a right way? How do I show a session that has multiple users and these users having completed multiple tests?

Here’s my code so far with regard to issue 1:

Session *session = [NSEntityDescription insertNewObjectForEntityForName:@"Session"
                                  inManagedObjectContext:context];
session.name = @"Session 1";

User *users = [NSEntityDescription insertNewObjectForEntityForName:@"User"
                                   inManagedObjectContext:context];
users.age = [NSNumber numberWithInt:28];
users.session = session;
//session.user = users;
[sessie addUserObject:users];

With regard to issue 2: I can log the session, but I can’t get the user(s) logged from a session.

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session"
                                          inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (Session *info in fetchedObjects) {
 NSLog(@"Name of session: %@", info.name);
 NSLog(@"Having problems with this: %@",info.user);
 //User *details = info.user;
 //NSLog(@"User: %@", details.age);
}
  • 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-15T22:51:19+00:00Added an answer on June 15, 2026 at 10:51 pm

    I find it useful (and it seems to be common practice from the code samples that I saw at SO), to use the plural form for to-many relationships, e.g. users for the to-many relationship from Session to User. It emphasizes the fact that the value of the relationship is a set and not a single object, and might make things a bit clearer.

    So your model would look like this:

    enter image description here

    Issue 1: If you have created a Session *session and a User *user, then

    user.session = session;
    

    adds the user to the session. Calling

    [session addUsersObject:user];
    

    has the same effect. But only one of these calls is required, it automatically implies the other, if the relationships are properly defined as inverse relationships.

    Issue 2: For a Session *session, session.users is the set of all users related to that session. It is a NSSet and you can iterate through that set. Similarly, user.tests is the set of all tests for a user.

    So the following code displays all sessions with their users and tests:

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session"
                                              inManagedObjectContext:context];
    [fetchRequest setEntity:entity];
    
    NSArray *sessions = [context executeFetchRequest:fetchRequest error:&error];
    for (Session *session in sessions) {
        NSLog(@"Name of session: %@", session.name);
        for (User *user in session.users) {
            NSLog(@"   User name %@, age %@", user.name, user.age);
            for (Test *test in user.tests) {
                NSLog(@"      Test: %@", test.name);
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three entities A, B, C. A has many Bs and a C,
I have three tables, Group -> User -> Account. Group can have multiple users
I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema
I have three entities. Author Newspaper Dissertation Newspaper and Dissertation both can have one
I have a case where i have three entities with one-to-many and one-to-many relationships:
Have three classes User, Group and Field. Many to many relationship on User /
I have three entities: Log, Employee, and Agency Log with a many to one
Lets say I have two entities: Stable , and Pony . Stable has an
hi i have two entities User and Authority they have many to many relation:
I have three entities: Country, State and City with the following relationships: When creating

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.