stefankroes / ancestry

Organise ActiveRecord model into a tree structure
MIT License
3.72k stars 458 forks source link

no definition for arrange in arrange_as_array #610

Closed mices closed 1 year ago

mices commented 1 year ago

what should the definition for arrange be to go along with arrange_as_array please?

kbrock commented 1 year ago

@mices you created a bunch of issues here.

I can't figure out if you found your answer. Could you close this if you have already found the answer to your question?

Also, all of these issues you have created are based around arrange_as_array. Could you keep all of this topic in a single issue rather than creating 5 of them?

Thank you

kbrock commented 1 year ago

is this related to #605 ?

mices commented 1 year ago

I copied and pasted arrange_as_array plus the code that follows up to and including possible_parents from your wiki page Creating a selectbox for a form using ancestry into my model and prepended self. to the definition For some unknown reason it causes an error on create which causes edit action and then it complains that it can't find a record without an id whereas previously the form had displayed with references to object in question just fine It just says block in arrange_as_array and doesn't give any further info

kbrock commented 1 year ago

please check out https://github.com/stefankroes/ancestry/blob/master/test/concerns/sort_by_ancestry_test.rb#L36-L43

If you do note, the code in https://github.com/stefankroes/ancestry/blob/master/lib/ancestry/class_methods.rb#L107 is very similar to the one in that wiki article

Let me know if that meets your needs. That test shows how to builds a tree and generates it.

Could you share your script that you are testing this with? Maybe we could update the wiki to meet people's needs better.

kbrock commented 1 year ago

ooh. arrange is part of the standard code.

arrange_as_array(Node.subtree.arrange)

any relation like children, descendants, and others works there.