core data - CoreData many-to-many relationship -
how operate many-to-many relationship in coredata? example:
i have 2 entities - recipes & ingredients
coredata links them recipes <<-->> ingredients. need add together attribute "count" every ingredient in recipe. how can it?
thanks
core info takes care of object graph consistency maintenance you. if utilize sqlite store, core info automatically creates intermediate bring together table many-to-many relationships. in case, should explicitly create intermediate (“join”) entity. advantage of intermediate entity can utilize add together more info relationship—for illustration “ingredientinfo” entity might include 'count' column. model should like: recipe <-->> ingredientinfo <<--> ingredient.
if find unclear here i'll update answer.
update: access ingredients , count
(ingredientinfo* ingredientinfo in recipe.ingredientinfos) { ingredient* ingredient = ingredientinfo.ingredient; nsnumber* count = ingredientinfo.count; }
or quick access ingredients in recipe utilize kvc
nsset* ingredients = [recipe valueforkeypath:@"ingredientinfo.ingredient"];
core-data many-to-many
No comments:
Post a Comment