Hi Stefan, Live has been so much easier since switching to ancestry! I'm enjoying the overhead reductions too! :)
Once thing I'm having trouble with is the output of .arrange. I'd expect it to respect the order defined in:
named_scope :ordered_by_ancestry, :order => "ancestry is not null, ancestry, position"
I've added this to my model as you suggested to add the position as part of the order. Doing this query:
parent.descendants(:to_depth => 2)
renders everything in the correct order (only not nested). Calling .arrange on that returns the nested hash but things are out of order. I'm not sure whether this is because ruby hashes don't haven an inherent order? What workarounds are there for this? :)
Looking forward to hearing from you,
added the possibility to pass an order option to arrange. This will only work for Ruby 1.9 and later since before that hashes don't have order.
Sweet, sounds good. You could always optionally use ActiveSupport::OrderedHash which does maintain an order, but relies on active_support. Thanks for the mod anyway :)
Great idea! That'll be in the next version.
Hi Stefan, just been playing with the new version of arrange, it works well, but I have run into a small edge case. I'm using other named scopes to further limit the records returned:
In some cases I'm not retrieving a parent due to a condition, but the children are still retrieved because they don't meet the condition, thus we have orphans to deal with. I'm going to have a go at modifying arrange to discard these orphans but thought it might be something you'd like to look at for future development also? I'll let you know what I come up with :)
Hi again, I've racked my brain trying to figure out how the arrange method works, but I just can't seem to make it click in my head :) If you have the time, and care :) I'd be grateful if you could explain how it is working. I can't see how orphans are getting inserted at the root of the hash structure :)