Comments (3)
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.
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.
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)
- anyone could give clarity to the readme? HOT 6
- Multiple root nodes HOT 1
- gui or gem for generic tree editing? HOT 3
- Make it easier to change the serialization format for the ancestry column HOT 11
- Do I still need to write an arrange_as_array routine to get a children inclusive ordered list? HOT 6
- release next version HOT 6
- having trouble displaying tree in select across different models/controllers
- How do i create a nested ancestry drop down collection_select list for rails forms? HOT 1
- [Idea] Remove InstanceMethods mixin HOT 4
- arrange_as_array causing unknown error HOT 7
- no definition for arrange in arrange_as_array HOT 5
- Falseful changelog, incorrect README and broken code in 4.3.0 HOT 23
- ancestor_ids_in_database removed? HOT 2
- Error in MaterializedPath2 descendants SQL? HOT 6
- Configuring Ancestry to use UUID keys HOT 4
- path_ids_in_database removed? HOT 5
- virtual depth_cache HOT 4
- Why is there no leafs method? HOT 1
- STI breaks arrange scoping HOT 3
- add support for virtual parent_id and root_id
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ancestry.