Coder Social home page Coder Social logo

Comments (4)

stefankroes avatar stefankroes commented on June 14, 2024

Your categories have not been nested properly. Check Category.find_by_name("Albacore").parent , it is probably nil.

On 5 jul 2011, at 16:34, jperrine wrote:

I have a rails 3.0.7 app with categories that are being nested within themselves using ancestry.

Steps to reproduce

Given I have the following categories nested within a category named "Health & Beauty"
Category "Albacore"
Category "Cream"

Calling Category.arrange returns the following nested hash

{
#<Category id: 37, name: "Albacore", created_at: "2011-07-05 14:27:30", updated_at: "2011-07-05 14:27:30", ancestry: "25">=>{},
#<Category id: 25, name: "Beauty and Hygiene", created_at: "2011-07-01 14:21:00", updated_at: "2011-07-01 14:21:00", ancestry: nil> =>
{
#<Category id: 38, name: "Cream", created_at: "2011-07-05 14:27:37", updated_at: "2011-07-05 14:27:37", ancestry: "25">=>{}
}
}

When I expect both "Cream" and "Albacore" to be returned within the "Beauty and Hygiene" ordered hash.

Reply to this email directly or view it on GitHub:
#60

from ancestry.

jperrine avatar jperrine commented on June 14, 2024
Category.find_by_name("Albacore").parent
 => #<Category id: 25, name: "Beauty and Hygiene", created_at: "2011-07-01 14:21:00", updated_at: "2011-07-01 14:21:00", ancestry: nil> 

It's nested properly, you can see the ancestry column in my original post which correctly has the id for "Beauty and Hygiene"

from ancestry.

stefankroes avatar stefankroes commented on June 14, 2024

Do you by any chance have a default scope that includes sorting?

If so change (example)

default_scope order(:name)

to (example)

default_scope order_by_ancestry_and(:name)

Alternatively you can use:

Category.with_exclusive_scope.arrange

Stefan

On 6 jul 2011, at 14:03, jperrine wrote:

Category.find_by_name("Albacore").parent
=> #<Category id: 25, name: "Beauty and Hygiene", created_at: "2011-07-01 14:21:00", updated_at: "2011-07-01 14:21:00", ancestry: nil>

It's nested properly, you can see the ancestry column in my original post which correctly has the id for "Beauty and Hygiene"

Reply to this email directly or view it on GitHub:
#60 (comment)

from ancestry.

jperrine avatar jperrine commented on June 14, 2024

That was the problem, thanks!

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.