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 7983099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:51:40+00:00 2026-06-04T10:51:40+00:00

I have a relation in Core Data like this: A -> B and the

  • 0

I have a relation in Core Data like this:

A -> B

and the following tables:

A
----
id 
path
ref_foreignkey_B

B
----
id
name

The problem is that the foreign key is set as B object (inherits from NSObject).

Then I am trying to fetch all entries from A where a reference to a certain B object is set. I know the object B but cannot figure out how to set the NSPredicate correctly.

I have tried the following:

NSString *complexPredicateFormat = [NSString stringWithFormat:@"ZREF_B == %@", self.B];   
NSPredicate *filter = [NSPredicate predicateWithFormat:complexPredicateFormat];
[fetchRequest setPredicate:filter];

… but that results in the following error:

'NSInvalidArgumentException', reason: 'Unable to parse the format string "ZREF_B == <B: 0x89d8300> (entity: B; id: 0x89d3ca0 <x-coredata://...

Does anyone know how to set a NSManagedObject (updated) as predict filter (represents the where clause)?

EDIT:
I am sorry. Of course A and also B inherits from NSManagedObject and NOT NSObject.

  • 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-04T10:51:42+00:00Added an answer on June 4, 2026 at 10:51 am

    Based on Gabriel suggestion:

    Have you created a Data Model? Why your entities subclass NSObject?

    Then

    If ref_foreignkey_B is a relationship for entity B you need to use

    [NSPredicate predicateWithFormat:@"ref_foreignkey_B == %@", self.B];
    

    Obviously if you use that predicate you need to query (use a fetch request) against A and not B.

    NSFetchRequest* fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"A"];
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"ref_foreignkey_B == %@", self.B];
    

    Some Notes

    Why do you use ZREF_B? This is the column created in the sqlite file (I suppose). You don’t have to use that but only properties (attributes or relationships) declared in the data model.

    id, path and ref_foreignkey_B for A

    id and name for B

    When you deal with Core Data you deal with an object graph and not with the db (sqlite for example) itself. This is an important point to understand. You have not to deal with the sqlite file (for example) that is created for you. Only with the data model you have created.

    In addition, I suggest you to create an inverse relationship from B to A. This lets you to maintain integrity in the object graph. For info read Relationships.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem decomposing a relation schema into a set of schemas that
I have a problem with Core Data. The problem happens with this scenario :
I have a relationship in a Core Data model that feels like it wants
I have Cinema table & City table and I have relation with this tables
I have two tables, Products and BundleProducts that have o2o relation with BaseProducts. A
I have a problem I cannot solve with a Core Data entity. In my
I have the following entities in core data as shown in the figure below.
I have a relation mapping table like this: attributeid bigint productid bigint To clean
I have a very strange problem with inverse relations in Core Data, and I
I have the following relation in my model: A user can have several consumers

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.