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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:16:37+00:00 2026-06-03T22:16:37+00:00

My model has an entity Filter and an entity Color. I want to have

  • 0

My model has an entity “Filter” and an entity “Color”. I want to have two “To-Many” relationships between them: “backgrounds” and “foregrounds”. (i.e. each “Filter” contains an array of background colors, and an array of foreground colors, all of type “Color”).

I have two problems. First, when I set up the relationships the inverse from “Color” can only have one value (I’m guessing this means I can’t do what I want). Second, I can’t figure out how I would create a predicate to fetch only the backgrounds or only the foregrounds. I assume the following will return all of them merged together (if it worked at all):

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Color"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"filter == %@", self];

I’m about to solve this by converting Color into two Foreground and Background entities, but I don’t want to do that without understanding why a single entity won’t work. Am I missing something here?

NOTE: This apparently is not intuitive to me. I came across this exact problem again, but this time I wasn’t using predicates so I didn’t find the problem right away. I had a very similar setup, but when I tried to remove a child it would initially go away, but when I restarted my app in would reappear more than once. The more children I removed, the more I ended up with. I eventually noticed the same children were in both relationship arrays, and when I looked at the graphical version of the model, only one of the relationships had an arrow connected to the child. Finally, I remembered I’d had this problem before! I don’t understand well what was happening, but apparent the two child “arrays” where merged together in a weird way.

  • 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-03T22:16:39+00:00Added an answer on June 3, 2026 at 10:16 pm

    Yes.

    Theory about multiple to-many relations

    Say you have the entity CHILD which is either a boy or a girl. Each child can have a set (to-many) of all their siblings. But each child could also have two more sets (to-many) of all their 1: brothers and 2: sisters.

    The reverse relation of "siblings" would be "isSiblingTo" (or siblings). And the reverse of "brothers" and "sisters" would be "isBrotherTo" and "isSisterTo".

    This was very simple since both entities where the same.

    Say instead I am a child who has a set of crayons and a set of toys. I probably have my red crayon in both these sets, i.e. I have to to-many relations to it.

    It all boils down to that the red crayon is both my CRAYON and my TOY.
    As with the sibling example above, a child’s brothers are both their siblings and their brothers and their sisters are both their siblings and their sisters.

    Update:

    You don’t need to be a part of both relations. You can have a child without the siblings relation but with both the brothers and sisters relations and the other children would have the reverse relations to them (this is closer to your color+filter example)

    Applied on your example

    So, if you have a use for it, it is doable. Just think of their relations in day-to-day language and set the reverse as isForegroundColorTo and isBackgroundColorTo.

    data model with multiple to-many relations
    data model with multiple to-many relations

    color model definition
    color model definition

    filter model definition
    filter model definition

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

Sidebar

Related Questions

So I have a repository for basically each entity but my model has a
We have an entity framework model with has some inheritance in it. The following
In my core data model I have a Person entity that has a to
I have an entity model where the base class in an inheritance structure has
In my business model I have Entity class (IPoint interface ) that has a
I have a vehicle entity in my data model. It has name, make, model,
I have a Group entity which has many Item entities. An Item entity can
I have a model (lets call it Entity) that has an attribute (Attribute) that
My Core Data model has two entities: Author and Book with a To-Many relationship
CoreData beginner I have a simple problem with CoreData. My model has two entities,

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.