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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:11:55+00:00 2026-05-27T03:11:55+00:00

I would like to separate my reference data from my user data in my

  • 0

I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part of my application). Therefore, I’ve been looking for a while for a way to code a cross-store relationship using fetched properties. I have not found any example implementations of this.

I have a Core Data model using 2 configurations :

  • data model config 1 : UserData (entities relative to user)

  • data model config 2 : ReferenceData (entities relative to application itself)

I set up 2 different SQLite persistent stores for both config.

  • UserData config (and store) contains entity “User”

  • ReferenceData config (and store) contains entities “Type” and “Item”.

I would like to create two single-way weak relationships as below :

  • A “User” has a unique “Type”

  • A “User” has many “Items”

Here are my questions :

  • How do I set up my properties?

  • Do I need 2 properties for each relation (one for storing Unique ID and another to access my fetched results)?

  • Could this weak relationship be ordered?

  • Could someone give me an example implementation of this?

As a follow-on to Marcus’ answer:

Looking through the forums and docs, I read that I should use the URI Representation of my entity instance instead of objectID. What is the reason behind this?

// Get the URI of my object to reference 
NSURL * uriObjectB [[myObjectB objectID] URIRepresentation];

Next, I wonder, how do I store my object B URI (NSURL) in my parent object A as a weak relationship? What attribute type should I use? How do I convert this? I heard about archive… ?

Then, later I should retrieve the managed object the same way (by unconvert/unarchive the URIRepresentation) and get Object from URI

// Get the Object ID from the URI 
NSManagedObjectID* idObjectB = [storeCoordinator managedObjectIDForURIRepresentation:[[myManagedObject objectID] URIRepresentation]];

// Get the Managed Object for the idOjectB ...

And last but not least, shouId I declare two properties in my entity A, one for persisting of URI needs and another for retrieving direclty object B?

NSURL * uriObjectB [objectA uriObjectB];

ObjectB * myObjectB = [objectA objectB];

As you can read, I really miss some simple example to implement thes weak relationships ! I would really appreciate some 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-27T03:11:55+00:00Added an answer on May 27, 2026 at 3:11 am

    Splitting the data is the right answer by far. Reference data should not be synced with the cloud, especially since iCloud has soft caps on what it will allow an application to sync and store in documents.

    To create soft references across to stores (they do not need to be SQLite but it is a good idea for general app performance) you will need to have some kind of unique key that can be referenced from the other side; a good old fashioned foreign key.

    From there you can create a fetched property in the model to reference the entity.

    While this relationship cannot be ordered directly you can create order via a sort index or if it has a logical sort then you can sort it once you retrieve the data (I use convenience methods for this that return a sorted array instead of a set).

    I can build up an example but you really are on the right track. The only fun part is migration. When you detect a migration situation you will need to migrate each store independently before you build up your core data stack. It sounds tricky but it really is not that hard to accomplish.

    Example

    Imagine you have a UserBar entity in the user store and a RefBar entity in the reference store. The RefBar will then have a fetchedProperty “relationship” with a UserBar thereby creating a ToOne relationship.

    UserBar
    ----------
    refBarID : NSInteger
    
    RefBar
    --------
    identifier : NSInteger
    

    You can then create a fetched property on the RefBar entity in the modeler with a predicate of:

    $FETCHED_PROPERTY.refBarID == identifier

    Lets name that predicate “userBarFetched”

    Now that will return an array so we want to add a convenience method to the RefBar

    @class UserBar;
    
    @interface RefBar : NSManagedObject
    
    - (UserBar*)userBar;
    
    @end
    
    @implementation RefBar
    
    - (UserBar*)userBar
    {
        NSArray *fetched = [self valueForKey:@"userBarFetched"];
        return [fetched lastObject];
    }
    
    @end
    

    To create a ToMany is the same except your convenience method would return an array and you would sort the array before returning it.

    As Heath Borders mentioned, it is possible to add a sort to the NSFetchedProperty if you want but you must do it in code. Personally I have always found it wasteful and don’t use that feature. It might be more useful if I could set the sort in the modeler.

    Using the ObjectID

    I do not recommend using the ObjectID or the URIRepresentation. The ObjectID (and therefore the URIRepresentation of that ObjectID) can and will change. Whenever you migrate a database that value will change. You are far better off creating a non-changing GUID.

    The weak relationship

    You only need a single value on the M side of the relationship and that stores the foreign identifier. In your object subclass you only need to implement accessors that retrieve the object (or objects).

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

Sidebar

Related Questions

We would like to publish a base model, that represents our core business data.
I would like to extract the data groups from the PHP arrays depending on
I would like to separate the API I'm working on into two sections: 'bare-bones'
I would like to separate my string by spaces, commas, periods (ie. punctuations). I
I am writing a video player on Linux and I would like to separate
I would like a batch file to launch two separate programs then have the
I would like to put a large variable definition in a separate file for
I have monthly sales figures stored in separate sheets. I would like to create
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it

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.