Bagusflyer
Bagusflyer

Reputation: 12925

How to design a tree like data structure in core data

I have a entity called "Category" and a entity called "item". Category may have one or more sub categories or have one or more items.

Here is what I designed.

enter image description here

But I have a special requirement. If the category has items, it won't have sub-categories. I don't know how to do this in my model design.

Any suggestions, thanks

Upvotes: 0

Views: 673

Answers (1)

Mundi
Mundi

Reputation: 80273

To my knowledge, there is no way to model this in the data model. You have to simply check for items before you create the subcategory.

Also, when deleting items, check if they leave any empty categories with (also empty) subcategories.

Upvotes: 1

Related Questions