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

  • Home
  • SEARCH
  • 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 8356755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:16:43+00:00 2026-06-09T10:16:43+00:00

I have two tables that I would like to get data and from by

  • 0

I have two tables that I would like to get data and from by seeing if they match a particular attribute.

I want to write a predicate or something like this but I do not seem to be able to come up with a solution: @"Data.item == Item.code".

The reason why I don’t use relationships is because my database was imported from mysql. So all the data is coming from outside of the app its being synced from downloaded mysql tables.

—————————EDIT————————-
What I have tried so far lots of things here is the crappy way I am doing this now perhaps from this you can understand more of what I am trying to do .

 NSPredicate * Newpredicate = [NSPredicate predicateWithFormat:@"hid == 2"];
    NSArray *row2 = [db DLook:Newpredicate table:@"Data"];
    for (NSManagedObject *data in row2) {
        NSLog(@"\n\n\n\nid\n\n\n\n: %@", [data valueForKey:@"id"]);
        NSString *itemToCode = [data valueForKey:@"item"];
        NSPredicate *itemPredicate = [NSPredicate predicateWithFormat:@"code == %@",itemToCode];
        NSArray *itemRow = [db DLook:itemPredicate table:@"Item"];
        for (NSManagedObject *item in itemRow) {
            NSLog(@"\n\n\n\ncode : %@\n\n\n\n",[item valueForKey:@"code"]);
        }
       // NSLog(@"id: %@", [data valueForKey:@"id"]);
        //NSManagedObject * itemhid= [data valueForKey:@"testRel"];
        //NSLog(@"code: %@",[itemhid valueForKey:@"code"]);
    }
    NSLog(@"\n\n\n\n%d\n\n\n\n",[row2 count]);

The DLook is a convince method that just fetches the data using the predicate on the table that I pass. Then take the returned area of NSmanaged objects looping through them.

I wish I could just make a magical relationship that would let me get a all the Item.data that match the Data.items!!!
I don’t want to do it like this I want to make a relationship that would work like that.

Help
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-06-09T10:16:44+00:00Added an answer on June 9, 2026 at 10:16 am

    Your equality in the predicate would only be true if the two objects are actually the same object. You could do this:

    [NSPredicate predicateWithFormat:@"item = %@", code];
    

    However, you should really try to get the relationships right when importing your model. Then you would not even have to do a fetch from the store but just use

    dataObject.item;
    

    So, when you import do something like this:

    // get one data object from your source
    // get the corresponding item object from your source
    Data *dataObject = [NSEntityDescription insertNewObjectForEntityForName:@"Data"
         inManagedObjectContext:self.managedObjectContext];
    Item *itemObject = [NSEntityDescription insertNewObjectForEntityForName:@"Item"
         inManagedObjectContext:self.managedObjectContext];
    [dataObject addItemObject:itemObject];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I want to fetch data from. Lets call them
So i have a query that is suppose to get me data from two
I was thinking that I would have two tables for mysql. One for storing
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,
Let's say I have two tables that look like this: TH TH TH TH
I need a query that loops data from two tables. The two tables I
I have two tables that link together through an id one is submit_moderate and
I have two tables that should be joined together by a foreign key relationship,
I have two tables that are considered a single entity in my domain model.

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.