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
Your equality in the predicate would only be true if the two objects are actually the same object. You could do this:
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
So, when you import do something like this: