Skip to content
Jon Gilkison edited this page Nov 12, 2012 · 3 revisions

ModelKit provides an interface for querying both the graph and your backend services for models. Both methods are exactly the same, though some caveats for backend services exist and will be discussed further in the documentation.

Let's take a look:

	-(void)someAction:(id)sender
	{
		MKitModelQuery *query=[CSMPAuthor query];
		
		// Let's find all authors between the ages of 24 to 35
		[query key:@"age" condition:KeyBetween value:@[@(24),@(35)]];
		
		NSDictionary *result=[query execute:nil];
		NSArray *found=[result objectForKey:MKitQueryResultKey];
		for(CSMPAuthor *author in found)
			NSLog(@"Author %@ is %d",author.name,author.age);
	}

That's a pretty simple example, but we can do more complicated queries using different conditions. Below is a list of conditions that the query supports:

Condition Meaning
KeyEquals ==
KeyNotEqual !=
KeyGreaterThanEqual >=
KeyGreaterThan >
KeyLessThan <
KeyLessThanEqual <=
KeyIn The value for the key is in an array of values
KeyNotIn The value for the key is not in an array of values
KeyExists The key value is not nil
KeyNotExist The key value is nil
KeyWithin The key value is within the range of two values
KeyBeginsWith The key value begins with a string value
KeyEndsWith The key value ends with a string value
KeyLike The key value contains the string

Queries are always AND and subqueries are not supported. Support for OR and subqueries is planned however.

Clone this wiki locally