Krishna,<br><br>That worked GREAT! Thanks for such a wonderful library! :D<br><br>Thanks,<br><br>--<br>Matt<br><br><div><span class="gmail_quote">On 8/14/07, <b class="gmail_sendername">Krishna Dole</b> &lt;<a href="mailto:dontfall@gmail.com">
dontfall@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hey Matt,<br><br>You were right-- there was a bug in the renumbering when working with
<br>virtual roots. I have fixed it in trunk. You can get the fixed version<br>with<br><br>script/plugin install svn://rubyforge.org/var/svn/betternestedset/trunk<br><br>Thanks for reporting this.<br><br>Krishna<br><br>On 8/14/07, Matt Rogish &lt;
<a href="mailto:rogishmn@muohio.edu">rogishmn@muohio.edu</a>&gt; wrote:<br>&gt; My guess is that there&#39;s a bug in the implementation of<br>&gt; renumber_full_tree/calc_numbers which is causing this problem. The dataset
<br>&gt; with overlapping numbers is what resulted from applying renumber_full_tree;<br>&gt; thus something is not quite right with that method...<br>&gt;<br>&gt; I have a copy of SQL for Smarties (2nd ed), so I&#39;ll try and see if the two
<br>&gt; algorithms diverge at all and/or provide a patch if I can help it. :)<br>&gt;<br>&gt; Thanks,<br>&gt;<br>&gt; --<br>&gt; Matt<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;On 8/14/07, Matt Rogish &lt;<a href="mailto:matt.rogish@gmail.com">
matt.rogish@gmail.com</a>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; The problem is, as I see it, overlapping left and right columns. Shouldn&#39;t<br>&gt; the lft/right be one apart, or am I wrong.<br>&gt; &gt;<br>&gt; &gt; For example:
<br>&gt; &gt; mysql&gt; select id, parent_id, lft, rgt from messages where message_board_id<br>&gt; = 1926 and parent_id is null order by lft;<br>&gt; &gt; +--------+-----------+------+------+<br>&gt; &gt; | id&nbsp;&nbsp;&nbsp;&nbsp; | parent_id | lft&nbsp;&nbsp;| rgt&nbsp;&nbsp;|
<br>&gt; &gt; +--------+-----------+------+------+<br>&gt; &gt; |&nbsp;&nbsp; 9472 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;&nbsp;&nbsp;1 |&nbsp;&nbsp;&nbsp;&nbsp;2 |<br>&gt; &gt; |&nbsp;&nbsp; 9473 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;&nbsp;&nbsp;2 |&nbsp;&nbsp; 37 |<br>&gt; &gt; |&nbsp;&nbsp; 9474 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp; 37 |&nbsp;&nbsp; 44 |<br>&gt; &gt; |&nbsp;&nbsp; 9475 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp; 44 |&nbsp;&nbsp; 45 |
<br>&gt; &gt; |&nbsp;&nbsp; 9476 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp; 45 |&nbsp;&nbsp; 74 |<br>&gt; &gt; |&nbsp;&nbsp; 9477 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp; 74 |&nbsp;&nbsp; 75 |<br>&gt; &gt; |&nbsp;&nbsp; 9478 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp; 75 |&nbsp;&nbsp;114 |<br>&gt; &gt; |&nbsp;&nbsp; 9487 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;114 |&nbsp;&nbsp;179 |<br>&gt; &gt; |&nbsp;&nbsp; 9479 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;179 |&nbsp;&nbsp;348 |
<br>&gt; &gt; |&nbsp;&nbsp; 9488 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;478 |&nbsp;&nbsp;515 |<br>&gt; &gt; |&nbsp;&nbsp; 9482 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;515 |&nbsp;&nbsp;520 |<br>&gt; &gt; |&nbsp;&nbsp; 9483 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;520 |&nbsp;&nbsp;525 |<br>&gt; &gt; |&nbsp;&nbsp; 9484 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;525 |&nbsp;&nbsp;526 |<br>&gt; &gt; |&nbsp;&nbsp; 9485 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;526 |&nbsp;&nbsp;579 |
<br>&gt; &gt; | 334881 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;579 |&nbsp;&nbsp;580 |<br>&gt; &gt; | 335201 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;581 |&nbsp;&nbsp;584 |<br>&gt; &gt; | 335234 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL |&nbsp;&nbsp;585 |&nbsp;&nbsp;586 |<br>&gt; &gt; +--------+-----------+------+------+<br>&gt; &gt;<br>&gt; &gt; So the only ones &quot;correct&quot;&nbsp;&nbsp;are id = 335201 and id = 335234?
<br>&gt; &gt;<br>&gt; &gt; I attached the entire dataset. What is happening is that the BETWEEN<br>&gt; statement that better nested set is executing looks something like this:<br>&gt; &gt; m = Message.find( 9478 )<br>&gt; &gt; 
m.all_children.each{ stuff }<br>&gt; &gt;<br>&gt; &gt; SQL is:<br>&gt; &gt; SELECT * FROM messages WHERE (message_board_id = 1926 AND (lft BETWEEN 75<br>&gt; AND 114)) ORDER BY lf<br>&gt; &gt;<br>&gt; &gt; Since BETWEEN is inclusive, that result pulls all the children correctly
<br>&gt; but incorrectly pulls out the next root, message id = 9487.<br>&gt; &gt;<br>&gt; &gt; I&#39;m not sure if that means renumber_entire_tree needs to be fixed, or the<br>&gt; actual move_to_child does, but something isn&#39;t right.
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt;<br>&gt; &gt; Matt<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On 8/14/07, Matt Rogish &lt;<a href="mailto:rogishmn@muohio.edu">rogishmn@muohio.edu</a>&gt; wrote:<br>&gt; &gt; &gt; I&#39;m not writing any SQL, I&#39;m using built-in better-nested-set functions.
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Here&#39;s my save:<br>&gt; &gt; &gt;&nbsp;&nbsp; def create<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; @message = Message.new(params[:message])<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; if @message.save<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flash[:notice] = &#39;Message was successfully created.&#39;
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if params[:message][:parent_id]<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @message.move_to_child_of( Message.find<br>&gt; params[:message][:parent_id] )<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @message.save<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt; &gt; &gt;&nbsp;&nbsp; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; --<br>&gt; &gt; &gt; Matt<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On 8/14/07, Jeremy Nicoll &lt;
<a href="mailto:jnicoll@goldnoteexpress.com">jnicoll@goldnoteexpress.com</a> &gt; wrote:<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; I think it would be best if you could post your SQL that is messed<br>&gt; up as well as the code you are using to save your nodes.&nbsp;&nbsp;Unfortunately we
<br>&gt; can&#39;t tell you what is wrong until we actually see the logic behind what you<br>&gt; are doing.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; --<br>&gt; &gt; &gt; &gt; Jeremy Nicoll<br>&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Matt Rogish wrote:<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; How can I repair my tree?<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; I have a message board system in which the messages are grouped by
<br>&gt; &quot;message_board_id&quot;, thus my model is:<br>&gt; &gt; &gt; &gt; acts_as_nested_set :scope =&gt; :message_board_id<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Somehow the tree is messed up, inasmuch as some roots (parent_id ==
<br>&gt; null) are being set to the children of some other message, so I cannot<br>&gt; successfully repair it. I&#39;m not sure if I&#39;m performing incorrect operations<br>&gt; or what, but somehow I need to repair my tree where message_board_id = 34
<br>&gt; (or whatever it is).<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; It seems as if renumber_full_tree tries to find the virtual root for a<br>&gt; given node, but since the root itself is a CHILD of another node, the whole
<br>&gt; thing fails. My layman&#39;s guess is that the &quot;root&quot; condition is wrong, since<br>&gt; it&#39;s doing WHERE parent_id IS NULL ... AND lft BETWEEN .. AND ..<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Well, if the root is incorrectly between something, then the lft would
<br>&gt; fail, no? Maybe I&#39;m misreading that. Help!!<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Thanks,<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; --<br>&gt; &gt; &gt; &gt; Matt<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;
<br>&gt; &gt; &gt; &gt; On 8/14/07, Matt Rogish &lt;<a href="mailto:rogishmn@muohio.edu">rogishmn@muohio.edu</a>&gt; wrote:<br>&gt; &gt; &gt; &gt; &gt; Under heavy load we are getting significantly screwed up data. I<br>&gt; have to run renumber_full_tree in script/console production order to repair
<br>&gt; the thing.<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; Obviously this is a bad thing, but I don&#39;t even know where to start<br>&gt; to fix it. Any ideas?<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; Thanks,
<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; --<br>&gt; &gt; &gt; &gt; &gt; Matt<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; ________________________________<br>&gt;<br>&gt; &gt; &gt; &gt; _______________________________________________
<br>&gt; &gt; &gt; &gt; Betternestedset-talk mailing list<br>&gt; &gt; &gt; &gt; <a href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; <a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a><br>&gt; &gt; &gt; &gt;
<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; &gt; Betternestedset-talk mailing list<br>&gt; &gt; &gt; &gt; <a href="mailto:Betternestedset-talk@rubyforge.org">
Betternestedset-talk@rubyforge.org</a><br>&gt; &gt; &gt; &gt;<br>&gt; <a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a><br>&gt; &gt; &gt; &gt;
<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Betternestedset-talk mailing list<br>&gt; 
<a href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a><br>&gt; <a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk
</a><br>&gt;<br>&gt;<br>_______________________________________________<br>Betternestedset-talk mailing list<br><a href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">
http://rubyforge.org/mailman/listinfo/betternestedset-talk</a><br></blockquote></div><br>