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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:30:39+00:00 2026-05-31T01:30:39+00:00

I have two entities: Login (user id, password) and Information (title, info). Now there

  • 0

I have two entities: Login (user id, password) and Information (title, info).
Now there is a 1 to 1 relation between them.
I need to add some information in the database unique to a user.

My code is below here:

    Login *information = [NSEntityDescription insertNewObjectForEntityForName:@"Login"
                                                      inManagedObjectContext:self.managedObjectContext];

    information.information.title = informationTitleTextView.text;
    information.information.info_1 = information1textview.text;
    information.information.info_2 = information2textview.text;

    [self.managedObjectContext save:nil];  // write to database

    [self.delegate savebuttontapped:self];

But It’s not Working.I don’t Know, What i am doing wrong?Any help would be appreciated.

  • 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-31T01:30:40+00:00Added an answer on May 31, 2026 at 1:30 am

    You haven’t added an instance of Information to the context. Try this:

    Login *login = [NSEntityDescription insertNewObjectForEntityForName:@"Login" inManagedObjectContext:self.managedObjectContext];
    Information *information = [NSEntityDescription insertNewObjectForEntityForName:@"Information" inManagedObjectContext:self.managedObjectContext];
    
    login.information = information;
    login.information.title = informationTitleTextView.text;
    //...and so on...
    

    Of course, if you’re going to fetch a Login object based on its attributes, you’ll want to actually store something in those attributes:

    login.userId = theUserId;
    login.password = thePassword;
    

    At some point in the future, you’ll probably want to fetch just the Login object that matches your criteria. Once you have that, you can get the associated information object without any trouble:

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Login"
        inManagedObjectContext:managedObjectContext];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userId like %@ AND password like %@", theUserId, thePassword];
    [request setPredicate:predicate];
    NSError *err = nil;
    NSArray *matchingLogins = [self.managedObjectContext executeFetchRequest:request error:&err];
    int count = [matchingLogins count];
    if (count != 1) {
        NSLog(@"Houston, we have a problem.");
    }
    Login *login = [matchingLogins objectAtIndex:0];
    Information *info = login.information; // Notice: no separate fetch needed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a entities as: BaseEntity --> Which contains user login info like createdBy,
There are times where I have to display the relationship between two entities. Question
I have two entities: User and Event. Each user has a list of events
I need a link between two entities, so I use a one-to-one @Entity @Table(name
i have two entities page and user. the page has a property userId on
I have two entities User and Event. Each user has a list of events
I have two entities one is Event and another is User. User can like
I have two entities Foo and Bar with a Many to Many relationship between
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer

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.