A lot of the time Threads are more useful than a hierarchy(plus threads is easier to spell), and luckily their not to hard to implement in og.
class SimpleThread is NestedSets property :thread, :Fixnum property :depth, :Fixnum pre :on => [:og_insert. :og_update] do |t| if t.parent.nil? t.depth = 0 t.thread = t.oid else t.depth = t.parent.depth.next t.thread = t.parent.thread end end end
As a caveat, I'm not a db expert or a nitro expert so there may be better ways to do this. There are some problems with this, specifically moving around chains, and there may be a fancy db layout that solves it. Anyway, once this is implemented it's the exact same as using NestedSets, as we've only added two properties.
SimpleThread.thread tells us the threads id; id est, how we can identify one threads from another. (you could change this to save something else) Thread.depth tells us how deep down the chain a child is.
To search the node we can simply use ez, and of course you could put this in a method to make it easier to use.
SimpleThread.find { |t| t.thread == 3 && t.depth <=> (3..4) }
I used the acts_as_threaded in rails as an inspiration(inspiration is a key word). Hopefully there aren't any bugs in my logic.