-
Notifications
You must be signed in to change notification settings - Fork 239
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
Negative position shows child before parent in roots_and_descendants_preordered
#49
Comments
Negative values aren't supported, but pull requests are. ;) (I think this would be pretty tricky/impossible to support, if you |
Are we sure on this? My experience is that |
@elhoyos you're completely correct, sorry about that: irb(main):002:0> l = Label.create(:name => "one")
=> #<Label id: 1, name: "one", type: nil, sort_order: nil, mother_id: nil>
irb(main):003:0> l.prepend_sibling(Label.new(:name => "zero"))
=> #<Label id: 2, name: "zero", type: nil, sort_order: -1, mother_id: nil> So—there's a couple things we can do. A) make the append_sibling/prepend_sibling functions ensure there are only positive order values that have no numeric gaps B) make Which sounds better? |
A) sounds cleaner and thus better. Juan David On Wed, Mar 20, 2013 at 11:24 PM, Matthew McEachen <[email protected]
|
B) sounds better for people that want to use ranked-model to generate the position |
Just looked at rank_model, and it would also require a synthetic |
"node1.append_sibling(node2) which will (...) increment the order_column of all children of node1's parents whose order_column is >= node2's new value by 1." Needless to say, that's not very efficient. How about letting people implement their own ordering. With ranked_model it would give something like: acts_as_tree :order => 'position'
include RankedModel
ranks :position, :with_same => :parent_id |
I'm in the process of switching from ancestry to closure_tree because of the bad interaction between acts_as_list and ancestry. They step on each others toes when deleting a branch of the tree because acts_as_list wants to reshuffle positions on surrounding nodes as they're deleted even though all the nodes eventually get deleted. This results in AR not found errors. I'd imagine this would be the case for any approach that had a separate ordering system as at the very least the tree system needs to make sure it destroys nodes starting from the leaves upward. The best case would be that the tree system knows about position and turns off compensation for removing nodes that it knows will be destroyed anyway. I'm not sure of the details of ranked_model but it appears to work in the same way as acts_as_list except for the consecutive position values. |
Just a little bit of followup. Would these be better scenarios for add_child, prepend_sibling, and append_sibling when using numeric deterministic ordering? ref_node.add_child(node)
ref_node.prepend_sibling(node)
ref_node.append_sibling(node)
I would have created some tests and a pull request but I had trouble getting a test suite set up. :) |
This is released in 4.0.1. |
This is still not working quite well with RankedModel, it works great before I adjust the position of an item, it breaks miserably after I adjust the position, and the new |
finally, i figured this part out with overwriting the method in the model, it's slow (because it's recursive), but it works
|
When position is negative the child showed before the parent in
roots_and_descendants_preordered
,self_and_descendants_preordered
it's behaving correctly (displaying Parent first, followed by its children)The text was updated successfully, but these errors were encountered: