Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Rails 3, a default_scope order("lft") breaks set_default_left_and_right #91

Closed
kofno opened this issue Oct 2, 2011 · 2 comments
Closed

Comments

@kofno
Copy link

kofno commented Oct 2, 2011

On rails 3, using SQLite:

Given the following class

class Item < ActiveRecord::Base
  acts_as_nested_set
  default_scope order("lft")
end

Then creating new items invalidates the tree.

This is because the default scope is included in the set_default_left_and_right scope, which breaks the calculation.

Here's my current work around:

class Item < ActiveRecord::Base

  ...

  protected

  def set_default_left_and_right
    Item.unscoped do
      super
    end
  end
end
@parndt
Copy link
Collaborator

parndt commented Oct 21, 2011

What can we do to fix this in the core?

@aserafin
Copy link

aserafin commented Dec 5, 2012

I had similar problem with using rebuild! function and having default_scope order("position asc") declared in my model. I've fixed it with adding

def rebuild!(validate_nodes = true)
  unscoped do
    #method code here
  end
end

@parndt parndt closed this as completed Dec 5, 2012
parndt pushed a commit that referenced this issue Dec 10, 2012
* Also added test for rebuild! action
* Fixes #165
* Fixes #91
@collectiveidea collectiveidea deleted a comment Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants