Chyba #1

avatar

NestedSet MoveTo-Method incorrect

Added by Martin Meel about 1 year ago. Updated about 1 year ago.

Status:Uzavřený Start:07/27/2010
Priority:Normální Due date:
Assigned to:- %% Done:

0%

Category:-
Target version:-

Description

Hi @ all,

I'm using your NestedSet-Plugin and I think I've located a bug in the MoveTo-Method.

I think the SQL here is not doing what it should do:

executeUpdate("update versioned NestedSet set lft=-lft, rgt=-rgt where objectClass='${className}' and setId=? and lft>=? and rgt<=?", [setId, node.lft, node.rgt])
            if (node.rgt > lft) {
                executeUpdate("update versioned NestedSet set lft=lft+? where objectClass='${className}' and setId=? and lft>=? and lft<=?", [node.rgt-node.lft+1, setId, lft, node.rgt])
                executeUpdate("update versioned NestedSet set rgt=rgt+? where objectClass='${className}' and setId=? and rgt>=? and rgt<=?", [node.rgt-node.lft+1, setId, lft, node.rgt])
            }
            else {
                executeUpdate("update versioned NestedSet set lft=lft-? where objectClass='${className}' and setId=? and lft>? and lft<?", [node.rgt-node.lft+1, setId, node.rgt, lft])
                executeUpdate("update versioned NestedSet set rgt=rgt-? where objectClass='${className}' and setId=? and rgt>? and rgt<?", [node.rgt-node.lft+1, setId, node.rgt, lft])
                lft-=node.rgt-node.lft+1
            }
            executeUpdate("update versioned NestedSet set lft=?-lft, rgt=?-rgt where objectClass='${className}' and setId=? and lft<0", [lft-node.lft,lft-node.lft,setId])
To recreate my situation, add 3 nodes with no parent:
id    version    object_class    object_id    parent_id    lft    rgt
1    0    nlet.Menu    1    NULL    1    2
2    0    nlet.Menu    2    NULL    3    4
3    0    nlet.Menu    3    NULL    5    6

Then move Node #1 to position 1.

The first SQL updates the lft & rgt of node #2 correct to -3 & -4:
id    version    object_class    object_id    parent_id    lft    rgt
2    1    nlet.Menu    2    NULL    -3    -4
1    0    nlet.Menu    1    NULL    1    2
3    0    nlet.Menu    3    NULL    5    6

But the following 2 lines do nothing.

The last line re-sets the lft & rgt of node # to it's initial value 3 & 4:
id    version    object_class    object_id    parent_id    lft    rgt
1    0    nlet.Menu    1    NULL    1    2
2    2    nlet.Menu    2    NULL    3    4
3    0    nlet.Menu    3    NULL    5    6

Hope you can help me.

Best wishes,
Martin Meel

History

Updated by Petr Mourek about 1 year ago

avatar

Martin Meel wrote:

I'm using your NestedSet-Plugin and I think I've located a bug in the MoveTo-Method.

It seems that moving a node within the same parent to a higher position is not consistent now. Will fix soon. Thanks for your report!

Updated by Martin Meel about 1 year ago

avatar

Moving a node to a higher position neems to work, but not to a lower position.
The problem is in the second part of SQL, not as I reported in the first part.

Until there's a fix, I've got a little workaround:

def moveTo(parent, position){
Map params = ['parent':parent, 'position':(position as Integer)]
/** * workaround because there's a little bug in the nestedSet-plugin. * @see http://www.grails.cz/issues/1 * @author key-work\mme
*/
def temp = new Menu(label: 'temp').save()
nestedSetMoveTo(temp)
nestedSetMoveTo(params)
temp.delete()
}

Updated by Martin Meel about 1 year ago

avatar

Seems to work as expected now.

Thank you for your very fast help!

Best wishes from Germany,
Martin Meel

Updated by Roman Mackovčák about 1 year ago

avatar
  • Status changed from Nový to Uzavřený

You are welcome. Closing the issue.

Updated by Martin Meel about 1 year ago

avatar

Hey,

it seems that there is still a problem with the moveTo-method.

I sometimes receive following message:
errors.GrailsExceptionResolver null
java.lang.NullPointerException at NestedSet$_injectToDomainClass_closure8.doCall(NestedSet.groovy:253)

Hope you can find the problem by simply moving/changing childs and parents.

Best wishes,
Martin Meel

Updated by Petr Mourek about 1 year ago

avatar

Unfortunatelly I can't reproduce this error by myself.

Also available in: Atom PDF