0
votes

hi i need to use coredata relations in my app. coredata relations is first tym for me. kindly guide me.

i need to have 2 entities "Products" and "reviews". for a single product there can be multiple reviews. i have 3 questions.

1) "product" entity is already containgin data. i need to add reviews to "reviews" entity later only. so how do i connect both the entities? the only thing common between both is the "product id".

2) if i delete a product how to delete all the reviews related to it from "reviews" entity.

3) can i delete the reviews without altering "products" entity

kindly help me. thanks in advance.

2

2 Answers

1
votes

The relationship between product and review is one to many. So create a relationship between the 2 entities, also set set the delete rule for product entity to “cascade”, so that when a product entity is deleted, the corresponding reviews for the products also gets deleted.

0
votes

You have to make relation for both entities and if you used NSArrayController to manage objected context you have to bind the Content set for the review to it's relation. then you can use the NSarraycontroller to control the objects that you added as review and delete them without affecting product's objects. Also,you have to bind managed objects as you app's delegate to manage Objected context.