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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:08:02+00:00 2026-05-13T17:08:02+00:00

I know how to create NSPredicate to do sql like SELECT * FROM DRINK

  • 0

I know how to create NSPredicate to do sql like "SELECT * FROM DRINK". But how about this query:

"SELECT I.name, D_I.amount 
FROM DRINK_INGREDIENT D_I, DRINK, INGREDIENT I 
WHERE D_I.drinkID=1 AND DRINK.drinkID=1 AND I.ingredientID = D_I.ingredientID;"  

How do I even set the NSEntityDescription, and NSPredicate for this kind of query?

  • 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-13T17:08:03+00:00Added an answer on May 13, 2026 at 5:08 pm

    Typically with Core Data you will design and use a data model that meets your needs. You should not think about it in terms of SQL–it does not even have to use SQL for storage–nor should you try to directly translate a SQL query into a fetch request with a predicate, etc.

    That said, it can sometimes be helpful to think in terms of SQL WHERE clauses when building predicates, but really fetch requests comes down to what entity you need to get and how the collection should be filtered and/or sorted, etc.

    Fetch requests are limited to a single entity, so I think you would need multiple fetch requests to simulate your query.

    What does your Core Data data model look like? What are you trying to accomplish? What have you tried so far?

    UPDATE
    It sounds like your data model includes two entities: Drink and Ingredient with a many-to-many relationship between them:

    Drink <<–>> Ingredient

    Note that in Core Data, there is no DrinkIngredient entity unless you explicitly create it (there is an additional table for the many-to-many relationship, but it’s abstracted away from you). Since you want an amount value associated with the rows in the additional table, I would recommend adding a DrinkIngredient entity in Core Data:

    Drink <–>> DrinkIngredient <<–> Ingredient

    Note: a DrinkIngredient has exactly one Drink and one Ingredient. Drinks can have many DrinkIngredients and Ingredients can be used by many DrinkIngredients.

    It sounds like you want to get the name and amount for the list of ingredients for a particular drink. To do this, simply fetch DrinkIngredient objects with a filter predicate like this:

    // assuming "aDrink" is a reference to a particular Drink object
    // and "drink" is the relationship from DrinkIngredient to Drink
    fetchRequest.predicate = [NSPredicate predicateWithFormat:@"drink == %@",aDrink];
    
    // if the fetch request result array is named "ingredientList"
    // and the relationship from DrinkIngredient to Ingredient is "ingredient"
    for (DrinkIngredient *di in ingredientList) {
        NSString *ingredientName = di.ingredient.name;
        NSUInteger amount = di.amount.integerValue;
    
        // use "ingredientName" and "amount" here
    }
    

    Since you are using Core Data and not SQL, you do things differently. For example, if you wanted to display an ingredient list with name and amount for all drinks, you would simply fetch all Drink objects (no filter predicate) and you access the ingredients through the relationship from Drink to DrinkIngredient.

    Again, you should think about what you are trying to accomplish and design and use your data model appropriately. You should not think about SQL or queries.

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

Sidebar

Related Questions

I know how to create a job dynamically from this create-sql-server-job-automatically The issue I
I know I can create a List<T> from IEnumerable<T> by doing myEnumerableCollection.ToList() , but
I know how to create an histogram in Python, but I would like that
I know how to create a PrintWriter and am able to take strings from
i would like to know how to fetch all events from an EventStore using
Would like to know create drop shadow for UINavigationbar. I tried to create custom
I know how to create a cookie that will expire after a certain amount
I was reading about refactoring a large slow SQL Query over here , and
I know how to create a SEL at compile time using @selector(MyMethodName:) but what
What kind of skills should a WPF developer know to create MVVM applications? Things

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.