You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using closure_tree order: "column", I get an ActiveRecord warning when I create a record that calls the ClosureTree::HierarchyMaintenance#rebuild! method.
Hi there,
When using
closure_tree order: "column"
, I get an ActiveRecord warning when I create a record that calls theClosureTree::HierarchyMaintenance#rebuild!
method.The offending line is the following line : https://github.com/ClosureTree/closure_tree/blob/master/lib/closure_tree/hierarchy_maintenance.rb#L85
Actually
closure_tree
, when called with the:order
keyword argument calls a method calledhas_many_order_with_option
(https://github.com/ClosureTree/closure_tree/blob/master/lib/closure_tree/support.rb#L91) which defines a default order scope on the:children
relation.As ActiveRecord does not support ordering scopes with
.find_each
(see here : https://github.com/rails/rails/blob/main/activerecord/lib/active_record/relation/batches.rb#L214-L216 and here : https://github.com/rails/rails/blob/main/activerecord/lib/active_record/relation/batches.rb#L286-L294), theHierarchyMaintenance#rebuild!
method throws a warning.One workaround is to call
.unscope(:order)
before calling the.find_each
method.Is this something that you'd want to fix ?
If so I can submit a PR for this.
The text was updated successfully, but these errors were encountered: