Skip to content
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

Warning : Scoped order is ignored, it's forced to be batch order. #378

Open
vala opened this issue Apr 20, 2021 · 0 comments
Open

Warning : Scoped order is ignored, it's forced to be batch order. #378

vala opened this issue Apr 20, 2021 · 0 comments

Comments

@vala
Copy link

vala commented Apr 20, 2021

Hi there,

When using closure_tree order: "column", I get an ActiveRecord warning when I create a record that calls the ClosureTree::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

children.find_each { |c| c.rebuild!(true) }

Actually closure_tree, when called with the :order keyword argument calls a method called has_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), the HierarchyMaintenance#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant