Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:48:37+00:00 2026-06-12T08:48:37+00:00

I have two entities. Employee entity @interface Employee : NSManagedObject @property (nonatomic, retain) NSString

  • 0

I have two entities. Employee entity

@interface Employee : NSManagedObject

@property (nonatomic, retain) NSString * dept;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Department *deptEmp;

@end

and Department entity

@interface Department : NSManagedObject

@property (nonatomic, retain) NSString * location;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Employee *deptEmp1;

I am trying to fetch information from both with following predicate

NSMutableString *queryString = [NSMutableString stringWithFormat:@"(name = 'Apple') AND (deptEmp1.location like 'Cupertino')"];

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];

And Fetch Request is

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
[request setResultType:NSDictionaryResultType]; // NSFetchRequestResultType - NSDictionaryResultType
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Department",nil]];
[request setIncludesSubentities:YES];

Setting Predicate

if(![queryString isEqualToString:@""])
{
        [request setPredicate:[NSPredicate predicateWithFormat:queryString]];
}

NSError *error = nil;
NSArray *returnArray = nil;

Fetching Result

@synchronized(self)
{
    returnArray = [self.managedObjectContext executeFetchRequest:request error:&error];
}

But here I never get result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:48:39+00:00Added an answer on June 12, 2026 at 8:48 am

    I’m not sure what you want to achieve but if you want to retrieve an Employee who works in a specific department name and in a specific location, I’ll use a the following code:

    NSMutableString *queryString = [NSMutableString stringWithFormat:@"deptEmp1.name == %@ AND deptEmp1.location == %@", @"Apple", @"Cupertino"]; 
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];
    [request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Department",nil]];
    [request setIncludesSubentities:YES];
    
    NSArray* returnArray = [self.managedObjectContext executeFetchRequest:request error:&error];
    if([returnArray count] > 0) {
    
       Employee* emp = [returnArray objectAtIndex:0];
       NSLog(@"%@ %@ %@", emp.name, emp.dept, emp.deptEmp.location);
    }
    

    Few notes

    Why do you use a lock on the request?
    Have you set a inverse rel?
    Maybe do you need to set up a one-to-many rel between Department and Employee?

    Try and let me know.

    Edit

    Try this one. I didn’t notice the query string in your question.

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"deptEmp1.name == %@ AND deptEmp1.location == %@", @"Apple", @"Cupertino"]; 
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];
    [request setPredicate:predicate];
    [request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Department",nil]];
    [request setIncludesSubentities:YES];
    
    NSArray* returnArray = [self.managedObjectContext executeFetchRequest:request error:&error];
    if([returnArray count] > 0) {
    
       Employee* emp = [returnArray objectAtIndex:0];
       NSLog(@"%@ %@ %@", emp.name, emp.dept, emp.deptEmp.location);
    }
    

    Edit 2

    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];
    
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];
    [request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Department",nil]];
    
    NSArray* returnArray = [self.managedObjectContext executeFetchRequest:request error:&error];
    for(Employee* emp in returnArray) {
    
       NSLog(@"%@", emp);
       NSLog(@"%@", emp.deptEmp);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee
I have a parent entity, Person, and two children entities : Caller and Employee.
I have two Entities: Group and Member : Entity name: Group Relationships: Member (inverse:Group)
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities types: RunContainer parent entity type Run child entity type Run
Let's assume I have two entities - project team and employee. Each employee could
Imagine if you will a Core Data app with two entities (Employee, and Department).
For example, I have two entities: Employee and Address. Of these enitities, Employee has
I have two entities in coredata: Voice described like: NSString *code NSString *description and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.