title: Core Data adding relationship by users
body: <p>I am stuck on a issue that I am having with core data, Once my app load the core data database gets create. I have a user entity that gets populated via the submit button on the login viewController if the credentials are correct. In the next View I take the return data from the login viewController and submit it to another URL. This gives me <code>JSON</code> return data which gets stored in the database as well. </p>
  
  <p>I have attached my data model and everything work fine except the user entity, I cannot for the life of me to get the right user to go with the data inside the connections.</p>
  
  <p><img src="https://i.stack.imgur.com/rnhru.png" alt="datamodel"></p>
  
  <p>These are my users 
  <img src="https://i.stack.imgur.com/0JCk1.png" alt="users"></p>
  
  <p>Each user has two records the below is what's getting stored, instead of all all 1's in the user column there should be two 1's and two 2's.</p>
  
  <p><img src="https://i.stack.imgur.com/PdQ4x.png" alt="table"></p>
  
  <p>Here is my code that I am using to store the data</p>
  
  <pre><code>  User *username = [User MR_findFirstByAttribute:@"username" withValue:currentUser];
    NSDictionary *parameters = @{@"DeviceKey": username.guid};
  
   [_operationManager POST:@"GetPrivateRssFeeds" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
  
    //I'm calling all the users with this piece
    NSArray *elements = [User MR_findAll];
    id attributes = [elements  valueForKey:@"username"];
  
    NSLog(@"user: %@",attributes);
    username.sessionKey =[[operation.responseObject objectForKey:@"Data"]objectForKey:@"sessionId"];
  
    id connections = [[operation.responseObject objectForKey:@"Data"]objectForKey:@"connections"];
    id connection;
  
     NSMutableArray *connectionArray = [NSMutableArray array];
    for(connection in connections)
    {
        //Get the JSON values
        NSString *contentSystemID = [connection objectForKey:@"contentSystemId"];
        NSString *contentSystemName = [connection objectForKey:@"name"];
        NSString *logoUrl =  [connection objectForKey:@"logo"];
        NSNumber *unreadCount = [connection objectForKey:@"unread_count"];
  
        FCConnection *connectionEntity = [FCConnection MR_createEntity];
        connectionEntity.contentSystemID   = contentSystemID;
        connectionEntity.contentSystemName = contentSystemName;
        connectionEntity.logoUrl = logoUrl;
        connectionEntity.unreadCount = unreadCount;
  
      // [user addConnections:connection];
         [connectionArray addObject:connection];
  
        id categories = [connection objectForKey:@"categories"];
  
        NSMutableArray *categoryArray = [NSMutableArray array];
  
        for (id cat in categories)
        {
            NSString *title = [cat valueForKey:@"name"];
            NSNumber *unreadCount = [cat valueForKey:@"unread_count"];
  
  
            FCCategory *category = [FCCategory MR_createEntity];
            category.title = title;
            category.unreadCount = unreadCount;
  
  
            id items = [cat objectForKey:@"items"];
  
  
  
  
            NSMutableArray *itemArray = [NSMutableArray array];
  
            for (id item in items)
            {
  
                NSNumber *isRead = [item valueForKey:@"unread"];
                NSString *title = [item valueForKey:@"title"];
                NSString *link = [item valueForKey:@"link"];
                NSString *systemID = [item valueForKey:@"itemId"];
               // BaseTopic *baseEntity = [A MR_createEntity];
               // baseEntity.title   = title;
                Article *article = [Article MR_createEntity];
                article.link = link;
                article.systemID = systemID;
                article.isRead = isRead;
  
                [article setValue:title forKey:@"title"];
                article.category = category;
  
                [itemArray addObject:article];
                  NSLog(@"item %@",itemArray);
            }
  
            [category addArticles:[NSSet setWithArray:itemArray]]; // mapping the items to category
             category.connection = connectionEntity;
            [categoryArray addObject:category];
        }
  
        connectionEntity.user = username;
        [connectionEntity addCategories:[NSSet setWithArray:categoryArray]]; // mapping the items to connection entity
  </code></pre>
  
  <p>How can I map the user to the connection?</p>