有如下关系表:
需要查询指定Dealer下的Acount里所有GoodsHide:
/**
* @brief 通过交易商CID与账户名获取当前用户设置的隐藏商品信息列表
*
* @param dealerCID 交易商CID
* @param accountName 账户名
*
* @return 当前用户设置的隐藏商品信息列表
*/
- (NSSet *)hidedGoodsCodeSetWithDealerCID:(NSString *)dealerCID accountName:(NSString *)accountName;
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:self.appDelegate.managedObjectContext];
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"accountName = %@",accountName];
[fetchRequest setPredicate:predicate];
//查询此账户名的所有账户信息
NSError *error = nil;
NSArray *array = [[[NSArray alloc] initWithArray:[self.appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&error]] autorelease];
if(!error){
//通过交易商过滤
NSPredicate *filter = [NSPredicate predicateWithFormat:@"inDealer.cid = %@",dealerCID];
NSArray *accountArray = [array filteredArrayUsingPredicate:filter];
if (accountArray.count > 0) {
//获取此账户隐藏商品信息列表
Account *account = [accountArray objectAtIndex:0];
return account.goodsHide;
} else {
return nil;
}
}
return nil;
}