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