Coder Social home page Coder Social logo

Comments (3)

stefankroes avatar stefankroes commented on June 7, 2024

having

model.send :default_scope, model.order('name')

breaks about half of all tests, also on rails 3.0, I don't understand why though: the testing models should be totally isolated

from ancestry.

petehamilton avatar petehamilton commented on June 7, 2024

I just experienced this as well, any further ideas?

Mine was when updating the ancestry property of several models and then asking for them to be arranged.

Here is a brief example and some information which might help.

Category Model (object I am nesting)

  default_scope :order => 'name ASC'

Then I have a function which prints a tree to the terminal.

  def printTerminalTreeForHash(categories, level = 0)
    categories.each do |c, cs|
      puts "   "*level + "|- #{c.name}, #{c.id}, #{c.ancestry},"
      if !cs.empty?
        printTerminalTreeForHash cs, level + 1
      end
    end
    return ""
  end

Which produces this style: |- name, id, ancestry

|- Root, 5, ,
   |- C1, 6, 5,
      |- C1.1, 7, 5/6,
         |- C1.1.1, 8, 5/6/7,
      |- C1.2, 10, 5/6,
         |- C1.1.2, 9, 5/6/10,
         |- C1.2.1, 11, 5/6/10,
         |- C1.2.2, 12, 5/6/10,

Somewhere I have code akin to the following:

printTerminalTreeForHash(@category.descendants.arrange)
@category.descendants.map{|c| "#{c.id}: #{c.ancestry}"}.inspect
puts @category.descendants.
#Update with the new ancestry (e.g. 1/2 => 1/2/3 if moved into subfolder)
@category.descendants.each {|c| c.update_attributes(ancestry: c.ancestry.gsub(old_ancestry, @category.ancestry))}
printTerminalTreeForHash(@category.descendants.arrange)

And I somehow end up with the following tree in my terminal:

|- C1, 6, 5,
   |- C1.1, 7, 5/6,
      |- C1.1.1, 8, 5/6/7,
   |- C1.1.2, 9, 5/6/10,
   |- C1.2, 10, 5/6,
      |- C1.2.1, 11, 5/6/10,
      |- C1.2.2, 12, 5/6/10,
|- C2, 13, 5,
   |- C2.1, 14, 5/13,
      |- C2.1.1, 15, 5/13/14,
      |- C2.1.2, 16, 5/13/14,
   |- C2.2, 17, 5/13,
   |- C2.2.1, 18, 5/13/19,
   |- C2.2.2, 19, 5/13,
|- Root, 5, ,

As you can see, the ancestry updated fine, but for some reason it's not nesting/arranging correctly (See second node from the bottom).

If I remove the default scope on my categories it all works fine. WEIRD.

from ancestry.

StefanH avatar StefanH commented on June 7, 2024

fixed in 2.0 by 8850dca. Arrange would break if there was a default scope with order. Arrange will now reorder to ignore the default scope, so it works but ignores the default scopes' ordering. To apply an order to arrange, use arrange(order: 'name ASC'). See also: #124

from ancestry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.