Fetch data from core data having relationships among entities

93 Views Asked by At

In my core data model, I have 2 entity like department and employee, dept entity has two attributes (deptId and deptName) and employee entity has 4 attributes (empId,empName,empAge,deptId). One dept may have n numbers of employees so the relationship is 1 to many.

Now I need to fetch data from employee table, like fetch all employee details who's department is "HR". So what will be my query to core data to fetch desired results?

1

There are 1 best solutions below

0
On

while creating the relationship between two entities,I think you have given relation ship name by using that name we can get objects.

-(void)getEmployeeListFromDB {

arrEmpList = [[NSMutableArray alloc]init];
arrEmpList = [(NSMutableArray *)[deptIdObj.relationshipFromDeptToEmployes allObjects] mutableCopy];

}