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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:42:55+00:00 2026-05-26T04:42:55+00:00

I am new to core data therefore I have got few questions. I’ll ask

  • 0

I am new to core data therefore I have got few questions. I’ll ask two

1) I have two entities named Team and TeamMembers. They have to-many relationship i.e. one team can have many members. First please take a look at following diagram and .h files of there models and let me know whether I have made correct to-many relationship between Team and TeamMembers (I have a feeling that I have made opposite relationship).

enter image description here

Teams.h

#import <CoreData/CoreData.h>

@class TeamMembers;

@interface Teams :  NSManagedObject  
{
}

@property (nonatomic, retain) NSString * team_name;
@property (nonatomic, retain) NSString * color;
@property (nonatomic, retain) NSString * points;
@property (nonatomic, retain) TeamMembers * members;

@end

TeamMembers.h

#import <CoreData/CoreData.h>

@class Teams;

@interface TeamMembers :  NSManagedObject  
{
}

@property (nonatomic, retain) NSString * member_name;
@property (nonatomic, retain) NSSet* teams;

@end


@interface TeamMembers (CoreDataGeneratedAccessors)
- (void)addTeamsObject:(Teams *)value;
- (void)removeTeamsObject:(Teams *)value;
- (void)addTeams:(NSSet *)value;
- (void)removeTeams:(NSSet *)value;

@end

2) Please I need sample code for inserting Team then inserting its team members. Also How to fetch team members of particular team.


EDITED
I am using following piece of code to insert into Teams and Team members entities but it is not returning all team members in NSSet. It is returning only one team member in the result set

    self.context = [del managedObjectContext];

            Teams *teamobj = [NSEntityDescription
                             insertNewObjectForEntityForName:@"Teams" 
                             inManagedObjectContext:context];
            teamobj.team_name = teamname.text;
            teamobj.color = [NSString stringWithFormat:@"%d", color];
            teamobj.points = [NSString stringWithFormat:@"%d", 0];

            for(UITextField *view in self.scrollview.subviews)
            {
                if([view isKindOfClass:[UITextField class]])
                {
                    if ([view tag] == 99) {
                        if (![view.text isEqualToString:@""]) {
                            noone = YES;
                            TeamMembers *teammember = [NSEntityDescription
                                              insertNewObjectForEntityForName:@"TeamMembers" 
                                              inManagedObjectContext:context];
                            teammember.member_name = view.text;
                            teammember.teams = teamobj;

                            [teamobj addMembersObject:teammember];
                        }
                    }
                }
            }
if (![context save:&error]) {
                NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"Unable to save team at the moment." delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
                [alert show];
                [alert release];            
            }
  • 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-26T04:42:56+00:00Added an answer on May 26, 2026 at 4:42 am

    Yes, you have made the opposite relationship. You have a team member having many teams and a team belonging to one member. You can tell by the arrows on the relationship line: the double arrow means ‘has many’ and the single arrow means ‘has one’ or ‘belongs to’ (read in the direction that the arrow is pointing).

    You should switch the direction in the model navigator, trash the existing generated classes then re-generate them.

    When you have the relationship set up correctly then you can use the generated accessors to add members to a team and retrieve members for a particular team.

    EDIT to show example of adding a new team member to a team:

    TeamMember *newTeamMember = [NSEntityDescription insertNewObjectForEntityForName:@"TeamMember" inManagedObjectContext:context];
    newTeamMember.team = <existing team managed object>
    

    It’s as simple as that. Core Data will make sure that the reverse relationship is updated automatically, so the teamMembers collection of the team will include the new member you just added.

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

Sidebar

Related Questions

I'm new with Core Data and I have some questions about how to do
I am new to core data .I have already performed insert and delete operations
So I'm fairly new to Core Data and KVO, but I have an NSManagedObject
I have few Core Data projects for MacOS started with Xcode 3 that behaves
I am new to Core Data. I have noticed that collection types are not
I have a view that creates a new core data managed object, and fills
I am fairly new to Core Data and have run into an issue which
I'm new to this Core Data business. I got a UITableViewController hooked up with
I'm new to iphone development and have this problem with Core Data. At the
I'm new to core data and try to get all children objects of various

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.