Permalink
Browse files

Add inContext variant for `+MR_propertiesNamed:`

Closes #773.
  • Loading branch information...
1 parent 09bf507 commit 9abf472f0551a2905c5d713c1807056daf51b9b8 @tonyarnold tonyarnold committed May 20, 2014
@@ -138,7 +138,7 @@ + (id) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attrib
[ed setExpression:ex];
// determine the type of attribute, required to set the expression return type
- NSAttributeDescription *attributeDescription = [[self MR_entityDescription] MR_attributeDescriptionForName:attributeName];
+ NSAttributeDescription *attributeDescription = [[self MR_entityDescriptionInContext:context] MR_attributeDescriptionForName:attributeName];
[ed setExpressionResultType:[attributeDescription attributeType]];
NSArray *properties = [NSArray arrayWithObject:ed];
@@ -171,7 +171,7 @@ + (NSArray *) MR_aggregateOperation:(NSString *)collectionOperator onAttribute:(
[expressionDescription setName:@"result"];
[expressionDescription setExpression:expression];
- NSAttributeDescription *attributeDescription = [[[self MR_entityDescription] attributesByName] objectForKey:attributeName];
+ NSAttributeDescription *attributeDescription = [[[self MR_entityDescriptionInContext:context] attributesByName] objectForKey:attributeName];
[expressionDescription setExpressionResultType:[attributeDescription attributeType]];
NSArray *properties = [NSArray arrayWithObjects:groupingKeyPath, expressionDescription, nil];
@@ -288,7 +288,7 @@ - (BOOL) MR_importValuesForKeysWithObject:(id)objectData
+ (id) MR_importFromObject:(id)objectData inContext:(NSManagedObjectContext *)context;
{
- NSAttributeDescription *primaryAttribute = [[self MR_entityDescription] MR_primaryAttributeToRelateBy];
+ NSAttributeDescription *primaryAttribute = [[self MR_entityDescriptionInContext:context] MR_primaryAttributeToRelateBy];
id value = [objectData MR_valueForAttribute:primaryAttribute];
@@ -221,7 +221,7 @@ + (instancetype) MR_findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(N
ascending:ascending
withPredicate:searchTerm
inContext:context];
- [request setPropertiesToFetch:[self MR_propertiesNamed:attributes]];
+ [request setPropertiesToFetch:[self MR_propertiesNamed:attributes inContext:context]];
return [self MR_executeFetchRequestAndReturnFirstObject:request inContext:context];
}
@@ -37,6 +37,7 @@
+ (NSEntityDescription *) MR_entityDescription;
+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context;
+ (NSArray *) MR_propertiesNamed:(NSArray *)properties;
++ (NSArray *) MR_propertiesNamed:(NSArray *)properties inContext:(NSManagedObjectContext *)context;
+ (instancetype) MR_createEntity;
+ (instancetype) MR_createEntityInContext:(NSManagedObjectContext *)context;
@@ -99,29 +99,37 @@ + (void) MR_performFetch:(NSFetchedResultsController *)controller
#endif
++ (NSEntityDescription *) MR_entityDescription
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ return [self MR_entityDescriptionInContext:[NSManagedObjectContext MR_contextForCurrentThread]];
+#pragma clang diagnostic pop
+}
+
+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context
{
NSString *entityName = [self MR_entityName];
return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}
-+ (NSEntityDescription *) MR_entityDescription
++ (NSArray *) MR_propertiesNamed:(NSArray *)properties
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- return [self MR_entityDescriptionInContext:[NSManagedObjectContext MR_contextForCurrentThread]];
+ return [self MR_propertiesNamed:properties inContext:[NSManagedObjectContext MR_contextForCurrentThread]];
#pragma clang diagnostic pop
}
-+ (NSArray *) MR_propertiesNamed:(NSArray *)properties
++ (NSArray *) MR_propertiesNamed:(NSArray *)properties inContext:(NSManagedObjectContext *)context
{
- NSEntityDescription *description = [self MR_entityDescription];
+ NSEntityDescription *description = [self MR_entityDescriptionInContext:context];
NSMutableArray *propertiesWanted = [NSMutableArray array];
-
+
if (properties)
{
NSDictionary *propDict = [description propertiesByName];
-
+
for (NSString *propertyName in properties)
{
NSPropertyDescription *property = [propDict objectForKey:propertyName];

0 comments on commit 9abf472

Please sign in to comment.