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

  • Home
  • SEARCH
  • 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 1078081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:40:19+00:00 2026-05-16T21:40:19+00:00

Lets say I have a core data model like this one: Item attributes: name

  • 0

Lets say I have a core data model like this one:

Item
attributes:
name
type
relationships:
properties

Property
attributes:
name
value
realationships:
item

Each Property is connected to one Item, and each Item many properties. One Property may look exactly the same as another.

I know the value of one Property and want to get the value of another Property from the same Items. So first i fetch all Properties with that value.

    NSEntityDescription *propEntity = [NSEntityDescription entityForName:@"Property" inManagedObjectContext:self.managedObjectContext];
    NSPredicate *propPredicate = [NSPredicate predicateWithFormat:@"name like 'someName' AND value like %@", value];          
    NSFetchRequest *propRequest = [[NSFetchRequest alloc] init];
    [propRequest setEntity:propEntity];
    [propRequest setPredicate:propPredicate];  
    NSError *error = nil;

    NSArray* properties = [self.managedObjectContext executeFetchRequest:propRequest error:&error];

This works fine and I get the expected number of objects in my array. So now I want to fetch all the items that has these properties:

    NSEntityDescription *itemEntity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:self.managedObjectContext];
    NSPredicate *itemPredicate = [NSPredicate predicateWithFormat:@"type like %@ AND ANY properties in %@", @"typeValue", properties];          
    NSFetchRequest *itemRequest = [[NSFetchRequest alloc] init];
    [itemRequest setEntity:itemEntity];
    [itemRequest setPredicate:itemPredicate];

    NSArray* items = [self.managedObjectContext executeFetchRequest:itemRequest error:&error];

This also works and I get the expected number of objects in the array. Now I have my items I want to have the values of a property with another name in these items and it’s here I encounter my problem:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Property" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setFetchBatchSize:20];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like 'someOtherName' AND ANY item in %@", items];

[fetchRequest setPredicate:predicate];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"value" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                                                                            managedObjectContext:self.managedObjectContext 
                                                                                            sectionNameKeyPath:@"value"
                                                                                            cacheName:@"Props"];

Now the FetchedResultsController’s fetchedObjects array includes all of the properties with someOtherName not just only the ones that has an item that is in the items array.

Have I missed something here? I have tried using

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like 'someOtherName' AND item in %@", items];

and

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like 'someOtherName' AND ALL item in %@", items];

but with the same result.

Why don’t I get just the properties that has item in items?

If it helps, I have the sql-query that would give the result I’m looking for:

Select distinct Property.value from Property where Property.name = 'someOtherName' and property.item in (Select Property.item from Property where Property.name = 'someName' and Property.value = 'someValueIGetFromTheUI')

Thanks in advance for any help.

  • 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-05-16T21:40:19+00:00Added an answer on May 16, 2026 at 9:40 pm

    I believe your SQL query

    /*
    
    SELECT DISTINCT Property.value 
    FROM Property 
    WHERE Property.name = 'someOtherName' 
    AND Property.item IN (SELECT Property.item from Property where Property.name = 'someName' 
                          AND Property.value = 'someValueIGetFromTheUI')
    */
    

    Translated to a Predicate for a fetch to use in your FRC

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == 'someOtherName' AND SUBQUERY(items, $item, $item.name == 'someName' AND $item.value == %@)", value];
    
    
    
    NSEntityDescription *propEntity = [NSEntityDescription entityForName:@"Property" inManagedObjectContext:self.managedObjectContext];
    
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    
    [fetchRequest setEntity:propEntity];
    [fetchRequest setReturnsDistinctResults:YES];
    [fetchRequest setPredicate:predicate]; // from above
    
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"value" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    
    [fetchRequest setSortDescriptors:sortDescriptors];
    
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"value" cacheName:@"Props"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can change the timeout like this: <system.web> <authentication mode="Forms">… May 17, 2026 at 1:56 am
  • Editorial Team
    Editorial Team added an answer There are tons of IE add-on sample code projects out… May 17, 2026 at 1:56 am
  • Editorial Team
    Editorial Team added an answer Because this would not be a useful utility. Since they… May 17, 2026 at 1:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a Core Data model setup like so: Blockbuster Entity To-Many relationship to
One thing I have in mind is, that datasets in Core Data (or lets
Using Core Data. Let's say we have models for Team and Player. Assume: -Each
Lets say i have a form which have the following : Name:TextBox Email:TextBox Age:TextBox
Lets say I have 2 tables: 1 with users and another one which keeps
Overall I'm loving Core Data so far, but there is one quirk in the
Ok. I have an array with multiple objects populated by my core data stack
Lets say i have a text file with following content: Hello! How are you?
Lets say I have 2 mobile phones which are 50 meters away from each
I'm working on my first Core Data project (on iPhone) and am really liking

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.