s73v3r
s73v3r

Reputation: 1751

CoreData model options selection tree

I have an application where the user selects a set of options, but the options available at each step depend on the previous options selected. The pathways of selections can be modeled as a tree, however, the options available after selecting option A would be different than options available after selecting option B. It might look something like this:

                       Option 1
                      /   |    \
                     /    |     \
                    /     |      \
                A,B,C    D,E      F,G,H
               /  |  \   / \      / |
              I  J,K  L  M  N,O  P  Q

I apologize for the crudity of this model; I didn't have time to build it to scale.

Basically, A user will be presented with an initial set of options. Each of these options can have a set of suboptions, which would be unique compared to if they selected one of the other sibling options. At the end of their selection, they will have a Product object.

I'm looking for advice on how to model this kind of hierarchy in CoreData. I'm thinking that the leaf nodes should be a Product object, and that the intermediate options should just be regular NSManagedObjects, with a list of suboptions that can be selected.

Upvotes: 0

Views: 100

Answers (1)

Caleb
Caleb

Reputation: 125007

Sounds like you might want an entity to represent a decision, with to-many relationships with itself and with a product entity. Something like:

entity: Decision
    relationship: decisions ->> Decision
    relationship: product ->> Product

entity: Product
    attribute: name
    attribute: price
    attribute: color
    ...

That way, one decision can lead to one or more other decisions just as your "Option 1" node leads to three more decisions. Or, it can lead to one or more products, or to some combination of both.

Upvotes: 1

Related Questions