Perhaps you can try other methods to model parent-child relationship? 

These are related to Closure Table but also talk about other methods:

http://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree
http://dirtsimple.org/2010/11/simplest-way-to-do-tree-based-queries.html
http://karwin.blogspot.co.uk/2010/03/rendering-trees-with-closure-tables.html<http://karwin.blogspot.co.uk/2010/03/rendering-trees-with-closure-tables.html>

Storing Hierarchical Data in a Database (Adjacency List, Modified Preorder 
Tree Traversal and more reading materials at the end of the article)
http://www.sitepoint.com/hierarchical-data-database/ 

Adjacency List, Materialized Path, Nested Set and Closure Table
http://www.slideshare.net/billkarwin/models-for-hierarchical-data 

MPTT
https://groups.google.com/forum/?fromgroups=#!topic/web2py/Bw792rYt_nM 

On Monday, 4 March 2013 22:08:49 UTC, 黄祥 wrote:
>
> hi, 
>
> i want to show parent child tree using table that have self-reference. 
> actually i've tried the self-reference query, but the result is not i 
> expected, is there any idea for this?
>
> for example:
> *db.py*
> db.define_table('category',
>     Field('category', length=10, notnull=True, unique=True),
>     Field('parent', 'reference category'),
>     format='%(category)s')
>
> db.category.parent.requires=IS_EMPTY_OR(IS_IN_DB(db, 'category.category'))
>
> db.category.bulk_insert([{'category' : 'Monitor'}, 
>                          {'category' : 'Keyboard'},
>                          {'category' : 'Monitor LCD', 'parent' : '1'}, 
>                          {'category' : 'Monitor LED', 'parent' : '1'}, 
>                          {'category' : 'Keyboard Cable', 'parent' : '2'}, 
>                          {'category' : 'Keyboard Gaming', 'parent' : '2'}, 
>                          {'category' : 'Keyboard Wireless', 'parent' : 
> '2'}])
>
> *output i expected *
> Keyboard
> - Keyboard Cable
> - Keyboard Gaming
> - Keyboard Wireless
> Monitor
> - Monitor LCD
> - Monitor LED
>
> thank you so much in advance
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to