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

Order error with batches #316

Open
lukasedw opened this issue May 21, 2023 · 4 comments
Open

Order error with batches #316

lukasedw opened this issue May 21, 2023 · 4 comments

Comments

@lukasedw
Copy link

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.

@bogdan
Copy link
Owner

bogdan commented May 21, 2023

Can you show the grid source code?

@lukasedw
Copy link
Author

Sorry, it was my fault.

@bogdan
Copy link
Owner

bogdan commented May 23, 2023

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:

https://github.com/rails/rails/blob/311d0babfbacd105c2452339e9037e4a50400183/activerecord/lib/active_record/relation/batches.rb#L292

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.

@bogdan bogdan reopened this May 23, 2023
@bogdan
Copy link
Owner

bogdan commented May 23, 2023

@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?

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

2 participants