|
Posted by "Jared Williams" on 11/19/05 00:03
> Say I have an ancestry application where the users can enter
> parents, children, etc. The children have children, etc.
>
> table people
> id
> parent_id
>
> what is the best way to pull this from the db minimizing the
> number of queries to build a tree view of parents to children?
There is no simple way todo it with that model. (Unless you using Oracle, which has CONNECT BY, or I believe there is patch for
postgres to achieve similar).
If you have a lot more reads of the data, you may want to change to a nested set model, write operations take longer, but retrieving
the tree and rendering into a nested list only takes 1 query.
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html for details.
Jared
Navigation:
[Reply to this message]
|