I have a model, where I have an entity called “Category”. This Category has a one-to-many relationship called “Products”. How do I set up the fetch request to only get the Category entities WITHOUT the products?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
If you query against
Category, product elements are loaded as faults. This is the default behavior of CoreData.On the contrary if you use
- (void)setRelationshipKeyPathsForPrefetching:(NSArray *)keys, you can load (pre-fetch) products when the request is executed.From Core Data App
and
Edit
If you need to count the number of products for a specific category, use
- (NSUInteger)countForFetchRequest:(NSFetchRequest *)request error:(NSError **)errorusing a request like the following:where
toCategoryis the inverse relationship fromProductstoCategoryandcurrentCategoryis the category you have.