IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 3 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Either one of us is missing something, or Rails is magic
Unless I'm missing some major Rails magic, that's not an implementation of [link|http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=235427|nested set trees]. But then I don't see how you're even getting the children for the "each" in nested_display.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
Expand Edited by drewk Nov. 29, 2005, 12:23:04 PM EST
New I Missed Something
that's not an implementation of nested set trees

Sorry, I missed the 'nested set' portion of the request. What I supplied was an adjacency list implementation (according to the link you sent ... thanks BTW).

But then I don't see how you're even getting the children for the "each" in nested_display.

The acts_as_tree method defines a bunch of methods in your model object, including children, siblings, self_and_siblings, and ancestors. It also defines a roots method in the class object.

Theoretically, you would just create a acts_as_nested_set method that could create all the same methods, but using the nested set implementation. I'll have to review your linked article in more detail before I could say how easy that might be.
--
-- Jim Weirich jim@weirichhouse.org [link|http://onestepback.org|http://onestepback.org]
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
New Adjacency trees are simple.
Almost all ORM implementations can handle simple parent/child relationships. Nested set trees, though, as you can see from Drew's link, are a different animal. Of interest will be the code to insert/remove children, since that operaton would be prohibitively expensive if it required a SQL call for each child being modified.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Re: Adjacency trees are simple.
Of interest will be the code to insert/remove children, since that operaton would be prohibitively expensive if it required a SQL call for each child being modified.

So I see. It looks as if this is more of a "can the database support this" question than an ActiveRecord question. You can specify arbitrary SQL to be run on any given insert/update/delete action on ActiveRecord, so its just a matter of getting the SQL right.

But not all database handle those fancy SQL routines, right? (As I disclaimed in my other message, I am not a DB expert). Sothen it becomes a DB portability issue.

Is that the kind of answer you are looking for? (I'm willing to play with this idea, but since this will be more than a two minute demo, I want to make sure I'm addressing your concerns).
--
-- Jim Weirich jim@weirichhouse.org [link|http://onestepback.org|http://onestepback.org]
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
New The arbitrary SQL somewhat answers my question...
But since the arbitrary SQL that gets run will update every other record in a thread (in this example), I'm interested to see how ActiveRecord handles the results, particularly with respect to caching and the like.

At the very least you don't have to run code that would cause every object in the thread to save itself individually, which is good.

Note: just about any database can support a nested set tree. If it can't, then it's not much of a database. The only difference would be whether the logic can be placed in a stored procedure or not, but in the end that's not a big deal for the purposes of this example.

Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Not what he meant
From your example, it looks like the concept of walking the tree is handled automagically. In the set tree model you have updates something like:
update comments set lft = lft + 1 where lft > input1 and rgt < input2

If Rails typically hides SQL details from you, requiring you to walk the tree, this becomes a problem.
===

Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats].
[link|http://DocHope.com|http://DocHope.com]
New Re: Not what he meant
If Rails typically hides SQL details from you, requiring you to walk the tree, this becomes a problem.

ActiveRecord (the Rails ORM) is just a very thin layer of code on top of SQL. This makes it dirt easy to customize the SQL for fetching or updating. I don't think this will be a problem.

However, I'm not a heavy-duty user of AR, so it will be fun to play with this and see exactly how this all falls out.
--
-- Jim Weirich jim@weirichhouse.org [link|http://onestepback.org|http://onestepback.org]
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
     How do you manage database changes? - (admin) - (21)
         Re: How do you manage database changes? - (JimWeirich) - (11)
             Mind responding to some rails criticism? - (ben_tilly) - (10)
                 I would be interested to see... - (admin) - (8)
                     A Nested Comments Example - (JimWeirich) - (7)
                         Either one of us is missing something, or Rails is magic - (drewk) - (6)
                             I Missed Something - (JimWeirich) - (5)
                                 Adjacency trees are simple. - (admin) - (4)
                                     Re: Adjacency trees are simple. - (JimWeirich) - (3)
                                         The arbitrary SQL somewhat answers my question... - (admin)
                                         Not what he meant - (drewk) - (1)
                                             Re: Not what he meant - (JimWeirich)
                 Re: Mind responding to some rails criticism? - (JimWeirich)
         Weekly change scripts - (Yendor) - (3)
             We do something like that. - (static) - (2)
                 Oh, *that* process will scale well :-/ -NT - (drewk) - (1)
                     Tell me about it. - (static)
         We make them independent of code, and do them first - (ben_tilly) - (2)
             Automated or no? -NT - (admin) - (1)
                 No - (ben_tilly)
         Two answers - (tuberculosis)
         Re: How do you manage database changes? - (dws)

Would you like some Chocolate Foam with that Mercedes, sir?
260 ms