Order error with batches
Opened this issue · 4 comments
I am using this gem API to build a datatable endpoint on graphql. While testing some things I saw that this was not working:
::Chat::IndexGrid.new(order: "name", descending: false).data_hash
It was not ordered. Then I started to debug, I notice the condition on lib/datagrid/columns.rb:490, when using the batch each it is not considered the order of the asset. I can debug more later, but for now, thats what I have.
A workaround is set self.batch_size = 0.
Can you show the grid source code?
Sorry, it was my fault.
I actually can reproduce this issue. The order is really ignored when using batches. It seems like this is a rails batches design that can not be turned off:
I think it is bad: Rails should allow a custom order when using batches. I don't see any way to override this behaviour on the datagrid level within rails (even with monkey patch/power hacking).
So, currently the only idea is submit a PR into rails that would allow to keep relation order.
@zhuravel, I would want to know your opinion on the subject as I believe you are extensively using datagrid with batches in your project.
Rails basically ignores the relation order when using batches: https://github.com/rails/rails/blob/311d0babfbacd105c2452339e9037e4a50400183/activerecord/lib/active_record/relation/batches.rb#L292
Did you notice that behaviour? Does it cause issues for you? Do you have a workaround or best practice?