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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:17:30+00:00 2026-06-17T02:17:30+00:00

I am wondering how this works, if I create a Car object, and there

  • 0

I am wondering how this works, if I create a Car object, and there is a relationship called toParts (that has a set of all car parts for this car), and then I create another car, will it duplicate the toParts set?

add to core data:
car a = (toParts = wheel, tire, seat)

add to core data:
car b = (toParts = wheel, tire, seat)

CarParts.h (has a name attribute)

will I now have Carparts = wheel , wheel, tire, tire, seat, seat
If so do I need the duplicates? is there a way to just point all future cars to the same wheel instance (as opposed to having 1000 of them)?

thanks in advance

edited added code:

This is the code I am using to get the results right now, I was looking to get ris of the duplicates and get an end array of cars NOT carParts (but I want to search by carPart)

-(NSArray*) loadCarsFromCoreDataUsingCarParts:(NSMutableArray*)inputCarParts{
    NSLog(@"carParts =%@",inputCarParts);
    NSFetchRequest *fetchRequest =[[NSFetchRequest alloc]init];
    //To find the Cars we are using the carParts
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"CarPart" inManagedObjectContext:[self managedObjectContext]];

    //sets up fetch request details
    [fetchRequest setEntity:entity];
    //3 here signifies it is an ingredient search
    [fetchRequest setPredicate:[self parseSearchObjectsIntoAPredicate:inputCarParts:3]];
    //don’t understand these results so comment out
    //[fetchRequest setReturnsDistinctResults:YES];
    //[fetchRequest setResultType:NSDictionaryResultType];
    //attempt to preload the nsset containing the cars (just one each time for some reason
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"ToCar", nil]];

    //Perform fetch
    NSError *error;
    NSArray *records = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];

//I have to do this to get the results finally as cars NOT individual instances of car parts
    return [self convertToCars:records];
}


-(NSArray*)convertToCars:(NSArray*)records{
    NSMutableArray *manipulator =[NSMutableArray arrayWithArray:records];
    NSMutableArray *convertedArray =[[NSMutableArray alloc]init];

    for (int i=0; i<[manipulator count]; i++) {
        //regular way
        CarPart *partFromManipulator=(CarPart *)[manipulator objectAtIndex:i];
        [convertedArray addObjectsFromArray:[[ partFromManipulator toCar]allObjects]];
    }

    NSLog(@"Results from core data = %i",[convertedArray count]);
    return [NSArray arrayWithArray:convertedArray];
}
  • 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-17T02:17:31+00:00Added an answer on June 17, 2026 at 2:17 am

    Core Data doesn’t care if you create duplicate entries. There’s no automatic detection of two objects having identical attribute values– because you might want those. If you create two identical wheel entries, you’ll get two of them.

    Do you need them? Only you can answer that. It depends on how your app works. Is there ever a situation where those two wheel objects might be modified so that they’re not different? Does it make sense to have multiple car objects referencing the same wheel? The answer depends on what your app does and how it uses this data. I don’t know how your app works but my gut feeling is that if wheel actually refers to a wheel type– e.g. “Bridgestone Blizzak DM-V1 – 245/60R18 105R BSW”, then it makes sense to allow more than one car to use it. If it refers to a specific instance of a wheel– “right-rear tire on this particular car”, then it doesn’t make sense. But only you can say for sure.

    If you don’t need them, then sure, you can arrange for multiple cars to point to the same wheel. Make the wheel relationship to car a to-many relationship, and then associate one wheel which as many cars as you like. This doesn’t mean Core Data will start automatically detecting duplicate wheels– it never does that. But it does mean that if you keep the same wheel object around, you can use it for more than one car.

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

Sidebar

Related Questions

I'd like to create a vector struct in D that works like this: vec
I was wondering if anyone knows how this type of layout works http://500px.com/ Or
I'm wondering how to best tackle this, since what I have now works great
I'm wondering about the behind the scenes magic that's happening when you create a
I have a WPF application that allows users to create questions of all different
Just wondering why this works: window.NewListView = Backbone.View.extend({ template: _.template('<a href=/list class=button new-list>Create New
How much of this is auto-generated methods in Rails User.find_or_create_from_auth_hash(auth_hash). That is just wondering
I'm experimenting with knockout and the mapping plugin and wondering why this doesn't work.
I was discussing this at work, and was wondering where people start their designs?
I'm a beginner programmer, and am wondering how to work around this issue. The

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.