> I was wondering which is the best way to model a tree-looking
> structure with SqlAlchemy.

I've spent a lot of time dealing with different types of hierarchies
in SQLAlchemy lately...

One way is to use the "nested sets" model.  This does a decent job at
modelling hierarchies, at least as long as you don't have the same
leaf in the tree at multiple locations.

Some links describing nested sets:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
http://en.wikipedia.org/wiki/Nested_set_model

And here is a decent example of how to do this in sqlalchemy:
http://www.sqlalchemy.org/trac/browser/examples/adjacency_list/adjacency_list.py

The 'classic' way is the 'adjacency list' model.  Here is an
sqlalchemy example:
http://www.sqlalchemy.org/trac/browser/examples/adjacency_list/adjacency_list.py

You can also look up another pattern that seems to get labelled as
'materialized path'.  No clean sqlalchemy example I know of, but the
concept is easy:
http://www.google.ca/search?q=(hierarchical+OR+hierarchy)+materialized+path

Good luck!
Russ

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to