Ticket #35 (new defect)

Opened 1 year ago

Last modified 1 year ago

maxright query should not be scoped on before_create

Reported by: rails Assigned to: jcm
Priority: major Milestone:
Component: plugin Version: trunk
Keywords: maxright scopr before_create Cc:

Description

Hi, I used :scope => :root option, and realized that new root items were given [1,2] as boundaries : I might have error in my code. However, I had a look at the before_create method and I think condition are unnecesary : as the comment says, we just want to put it to the end of the tree. Anyway, it's move_to later.

Thus, I just remove condition : :conditions => acts_as_nested_set_options[:scope] (r.9 l.139)

 # on creation, set automatically lft and rgt to the end of the tree
 def before_create
    maxright = self.class.maximum(acts_as_nested_set_options[:right_column]) || 0
    # adds the new node to the right of all existing nodes
    self[acts_as_nested_set_options[:left_column]] = maxright+1
    self[acts_as_nested_set_options[:right_column]] = maxright+2
 end

Wish it helps,

Regards,

Change History

(in reply to: ↑ description ) 09/26/07 05:14:00 changed by rails

Replying to rails:

I think condition are unnecesary : as the comment says, we just want to put it to the end of the tree. Anyway, it's move_to later.

Just to add that if there's no reason to keep it, such a condition may only disturb data integrity in nested_set.