FetchObjectsForRelationshipSelector:

From EOFWiki
Jump to navigationJump to search

This method doesn't exist in EOF but could be coded this way:

- (NSArray *) _fetchObjectsForRelationshipSelector:(SEL) sel
{
   NSArray                *array;
   EOFetchSpecification   *fetch;
   EOQualifier            *q;
   EOClassDescription     *desc;
   EOClassDescription     *dstDesc;
   NSString               *dstKey;
   NSString               *key;

   key  = NSStringFromSelector( sel);

   // get our class description, figure out what target entity
   // is used and what the back relationship is
   desc    = [self eoClassDescription];
   dstDesc = [desc classDescriptionForDestinationKey:key];
   dstKey  = [desc inverseForRelationshipKey:key];

   // construct qualifier to fetch
   q = [[[EOKeyValueQualifier alloc] initWithKey:dstKey
                                operatorSelector:EOQualifierOperatorEqual
                                           value:self] autorelease];

   fetch = [EOFetchSpecification fetchSpecificationWithEntityName:[dstDesc entityName]
                                                        qualifier:q 
                                                    sortOrderings:nil]; 
   array = [[self editingContext] objectsWithFetchSpecification:fetch];
   return( array);
}