Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jul 6, 2006, 06:45 AM   #1
macrumors 6502a
Join Date: Jun 2005
Location: West-Europe
relationship predicate

What is missing? I think I do everything according to the manual.
Say I have entity A en B with a relationship REL (to many) from A to B but without an inverse one. B has a bool value of selected.
The user can select any B for each A and when this happens I observe the
and do some stuff I want to do. For this I need all the A's that has at least one selected B.

My solution to this is:
- (NSArray *) filterDatabase:(NSPredicate *) myPredicate forEntity:(NSString *)myEntity
	NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
	NSEntityDescription *entity = [NSEntityDescription entityForName:myEntity
	[request setEntity:entity];
	[request setPredicate:myPredicate];
	NSError *error = nil;
	NSArray *array = [context executeFetchRequest:request error:&error];
	if (error)
	return array;


	NSPredicate *selRec = [NSPredicate predicateWithFormat:@"ANY REL.selected == 1"];
	NSArray *result = [self filterDatabase:selRec
	NSLog(@"r %i",[result count]);
	NSPredicate *selRec3 = [NSPredicate predicateWithFormat:@"selected == 1"];
	NSArray *result3 = [self filterDatabase:selRec3
	NSLog(@"r3 %i",[result3 count]);
Every time something is selected, result3 is updated (as I can see with the NSLog), but the first 'result' doesn't give the right answer.

So, besides it being spaghetticode, what's wrong with it?

MrFusion is offline   0 Reply With Quote
Old Jul 6, 2006, 04:53 PM   #2
Thread Starter
macrumors 6502a
Join Date: Jun 2005
Location: West-Europe
The code above was right it seems and gave the correct answers. What was displayed was incorrect. When I load the database all instances of B are displayed at first until the selection of instance A is changed.
arraycontroller 1 is bound to A, and arraycontroller 2 is bound to the selection of A for the relationship from A to B.
MrFusion is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSArrayController predicates with Core Data Relationships timbos Mac Programming 1 Aug 31, 2011 06:10 PM
question with date/time comparison with predicate in core data jliu69 iPhone/iPad Programming 0 Jun 23, 2009 10:00 PM
NSSearchField switching Predicates MacDonaldsd Mac Programming 1 Jul 22, 2008 04:08 PM
Advanced use of NSSearchField's predicate binding Nutter Mac Programming 9 May 21, 2007 07:14 PM
predicate mixing characters and numbers MrFusion Mac Programming 0 Aug 1, 2006 06:13 AM

All times are GMT -5. The time now is 06:06 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC