<span class="gmail_quote"></span>The problem is, as I see it, overlapping left and right columns. Shouldn&#39;t the lft/right be one apart, or am I wrong.<br><br>For example:<br><span style="font-family: courier new,monospace;">
mysql&gt; select id, parent_id, lft, rgt from messages where message_board_id = 1926 and parent_id is null order by lft;
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">+--------+-----------+------+------+</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

| id&nbsp;&nbsp;&nbsp;&nbsp; | parent_id | lft&nbsp; | rgt&nbsp; |</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">+--------+-----------+------+------+</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9472 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp;&nbsp; 1 |&nbsp;&nbsp;&nbsp; 2 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9473 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp;&nbsp; 2 |&nbsp;&nbsp; 37 | 
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9474 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp; 37 |&nbsp;&nbsp; 44 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

|&nbsp;&nbsp; 9475 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp; 44 |&nbsp;&nbsp; 45 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9476 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp; 45 |&nbsp;&nbsp; 74 | </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9477 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp; 74 |&nbsp;&nbsp; 75 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9478 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp;&nbsp; 75 |&nbsp; 114 | 
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9487 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 114 |&nbsp; 179 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

|&nbsp;&nbsp; 9479 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 179 |&nbsp; 348 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9488 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 478 |&nbsp; 515 | </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9482 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 515 |&nbsp; 520 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9483 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 520 |&nbsp; 525 | 
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">|&nbsp;&nbsp; 9484 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 525 |&nbsp; 526 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">

|&nbsp;&nbsp; 9485 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 526 |&nbsp; 579 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">| 334881 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 579 |&nbsp; 580 | </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">| 335201 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 581 |&nbsp; 584 | </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">| 335234 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL |&nbsp; 585 |&nbsp; 586 | 
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">+--------+-----------+------+------+</span><br><br>So the only ones &quot;correct&quot;&nbsp; are id = 335201 and id = 335234?
<br><br>I attached the entire dataset. What is happening is that the BETWEEN statement that better nested set is executing looks something like this:<br>m = Message.find( 9478 )<br><span style="font-family: courier new,monospace;">

</span>m.all_children.each{ stuff }<br><br>SQL is:<br>SELECT * FROM messages WHERE (message_board_id = 1926 AND (lft BETWEEN 75 AND 114)) ORDER BY lf<br><br>Since BETWEEN is inclusive, that result pulls all the children correctly but incorrectly pulls out the next root, message id = 9487.
<br><br>I&#39;m not sure if that means renumber_entire_tree needs to be fixed, or the actual move_to_child does, but something isn&#39;t right.<div><span class="e" id="q_11465a8a8d7bb734_1"><br><br>--<br>Matt<br><br><div>
<span class="gmail_quote">On 8/14/07, <b class="gmail_sendername">
Matt Rogish</b> &lt;<a href="mailto:rogishmn@muohio.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rogishmn@muohio.edu</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;">

I&#39;m not writing any SQL, I&#39;m using built-in better-nested-set functions.<br><br>Here&#39;s my save:<br>&nbsp; def create<br>&nbsp;&nbsp;&nbsp; @message = Message.new(params[:message])<br><br>&nbsp;&nbsp;&nbsp; if @message.save<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flash[:notice] = &#39;Message was successfully created.&#39;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if params[:message][:parent_id]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @message.move_to_child_of( Message.find params[:message][:parent_id] )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @message.save<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp; &nbsp; end<br>&nbsp; end<br><br>--<br><span>
Matt</span><div><span><br>
<br>
<div><span class="gmail_quote">On 8/14/07, <b class="gmail_sendername">Jeremy Nicoll</b> &lt;<a href="mailto:jnicoll@goldnoteexpress.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">jnicoll@goldnoteexpress.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;">



  
  

<div bgcolor="#ffffff" text="#000000">
&nbsp;&nbsp;&nbsp; I think it would be best if you could post your SQL that is messed
up as well as the code you are using to save your nodes.&nbsp; Unfortunately
we can&#39;t tell you what is wrong until we actually see the logic behind
what you are doing.<br>
<br>
--<br>
Jeremy Nicoll<br>
<br>
Matt Rogish wrote:
<blockquote type="cite"><div><span>How can I repair my tree?<br>
  <br>
I have a message board system in which the messages are grouped by
&quot;message_board_id&quot;, thus my model is:<br>
acts_as_nested_set :scope =&gt; :message_board_id <br>
  <br>
Somehow the tree is messed up, inasmuch as some roots (parent_id ==
null) are being set to the children of some other message, so I cannot
successfully repair it. I&#39;m not sure if I&#39;m performing incorrect
operations or what, but somehow I need to repair my tree where
message_board_id = 34 (or whatever it is).
  <br>
  <br>
It seems as if renumber_full_tree tries to find the virtual root for a
given node, but since the root itself is a CHILD of another node, the
whole thing fails. My layman&#39;s guess is that the &quot;root&quot; condition is
wrong, since it&#39;s doing WHERE parent_id IS NULL ... AND lft BETWEEN ..
AND ..
  <br>
  <br>
Well, if the root is incorrectly between something, then the lft would
fail, no? Maybe I&#39;m misreading that. Help!!<br>
  <br>
Thanks,<br>
  <br>
--<br>
Matt<br>
  <br>
  <div><span class="gmail_quote">On 8/14/07, <b class="gmail_sendername">
Matt Rogish</b> &lt;<a href="mailto:rogishmn@muohio.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rogishmn@muohio.edu</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;">Under
heavy load we are getting significantly screwed up data. I have to run
renumber_full_tree in script/console production order to repair the
thing.<br>
    <br>
Obviously this is a bad thing, but I don&#39;t even know where to start to
fix it. Any ideas?
    <br>
    <br>
Thanks,<br>
    <br>
--<br>
    <span>Matt<br>
    </span></blockquote>
  </div>
  <br>
  </span></div><pre><hr size="4" width="90%">
_______________________________________________<br>Betternestedset-talk mailing list<br><a href="mailto:Betternestedset-talk@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Betternestedset-talk@rubyforge.org
<br><br><br></a>
<a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a>
  </pre>
</blockquote>
</div>

<br>_______________________________________________<br>Betternestedset-talk mailing list<br><a href="mailto:Betternestedset-talk@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Betternestedset-talk@rubyforge.org
</a><br><a href="http://rubyforge.org/mailman/listinfo/betternestedset-talk" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a><br><br></blockquote>



</div><br>
</span></div></blockquote></div><br>
</span></div><br clear="all">