Forum OpenACS Q&A: Categories -- Perhaps I am missing something basic

I started working with categories at the behest of a few people saying it is the 'right' solution for what I was trying to do, but, I have run into a few problems.

If categories are hierarchial, how does one find out what the parent to a particular category is?  I can see it stored in the table, but there must be a method that I am missing.

When you get the map, it returns a 'level' -- however, with the three categories I've added, two with a parent of "", one with the parent of the 2nd, I get a level of 1, 2, and 3.  I guess this doesn't signify how deep the category is.

How does one find the immediate children of the current category?

Is there any code that uses categories that I could use as an example?

Posted by Jun Yamog on
Hi Chris,

In general hierarchical tables that is implemented with postgres on OpenACS has a tree_sortkey column.  And you can use tree_* plsql.

Here is are samples:*checkout*/openacs-4/contrib/packages/bcms/tcl/bcms-category-procs-postgresql.xql?rev=1.1

You may also want to look at Timo's categories as the cr_keywords is the older implementation and I know will be changed.

Posted by Jeff Davis on
The categories package uses a nested set representation for the tree, here is an article by Joe Celko on nested set trees.
Posted by Jade Rubick on
Chris, I've run into the same problem you have. I'm not really sure about an easy way to get the immediate children of the current category, etc.. through the API.

I had to do a join of against the underlying tables, and even then, I'm not sure I got exactly what I want. It's close enough now.