Open awh-tokyo opened 2 years ago
Thanks for posting the feature request!
How would the sorting be persisted? Could your model have a virtual no-op setter for :sorting_attribute
?
class NamedTreeNode
def no_op_sorting_attribute=(*)
# do nothing
end
def parent=(record)
# handle setting parent record
end
end
Note: This assumes I fully recall how this library works.
I'm revisiting this because I thought about it while trying to clean up some code. The problem with your suggestion is that the :sorting_attribute
is used as the sort order in index_as_sortable.rb:
ol do
item.send(options[:children_method]).order(options[:sorting_attribute]).each do |c|
build_nested_item(c)
end
end if tree?
Setting the sorting_attribute to no_op_sorting_attribute causes the SQL generated by ActiveRecord to sort by a nonexistent column.
My use case is that I would like a tree structure, but to have each level always sorted by name. I'd like to have the tree editor still work for easily setting parent/child relationships.
Currently I have to override the "sort" controller action so that it does not update the "position" field (which I have set to 'name'), or else all my objects get their name changed to numbers:
Could we have a config option that allows us to disable the
record.send "#{options[:sorting_attribute]}=", position
?