0

I have recently asked a question regarding a suitable data structure for a hierarchical website design. Looking at the other side, how would I achieve the following:

Parent
   - Make
      - Model 1
         - Child 1
         - Child 2
      - Model 1
         - Child 1
         - Child 2
      - Model 1
         - Child 1
         - Child 2

Child 1 + 2 will be the same for each model. I can represent hierarchical data using a parent/child node and recursion (Obviously not the best). Would I have to create a many to many association for each model to the repeated list or something?

Thanks!

2
  • And where does your question differ from you previous question? Commented Sep 12, 2012 at 20:53
  • The previous answers showed how to represent the OOP structure. Here I want to know the best way for storing the data in a mysql table with ... I presume ... multiple many-to-many associations. Commented Sep 12, 2012 at 20:57

1 Answer 1

0

create a node class that has a value, type, and parent

type can be "make", "model", "child" or parent... and the value can serve as a string holder, and you can still add children of any type to the child resulting in this

[node type=parent]
    [node type=make value="make1"]
        [node type=model value="model1"]
            [node type=child value="child1"]
                [node type="date-created"]
                [node type="some-field"]
             [node type=child value="child2"]
                [node type="date-created"]
                [node type="some-field"]

the only fields in node class beside parent and type should be fields that should be present in all nodes

Sign up to request clarification or add additional context in comments.

1 Comment

That basically is what i am going to do. I can represent the different leaves in a database table, reference a type and use a factory pattern to create the structure for a path. The selected array can be serialized and cached and re-used without a massive recursive function call every load. To deal with repeated nodes, im storing a unique list of nodes in a branches table and self joining using an association table to allow say date-created to be created one but associated to every model. I can then use the id field in he association table to store any data against a unique node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.