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

Sorting by association should not be allowed in MongoID #3051

Open
mltsy opened this issue Aug 3, 2018 · 0 comments
Open

Sorting by association should not be allowed in MongoID #3051

mltsy opened this issue Aug 3, 2018 · 0 comments

Comments

@mltsy
Copy link

mltsy commented Aug 3, 2018

Currently, the list views still offer the option to sort by belongs_to associations(and maybe others?), even if the database adapter is non-relational (e.g. MongoID). RailsAdmin then raises a RuntimeError, which is not easy to handle, since it doesn't have a more specific error class to target.

It looks like there is some code to try to disallow sorting by association for non-relational databases in the view here:
https://github.com/sferik/rails_admin/blob/5da7874fa606fd0a9627764482ff81833ef11921/app/views/rails_admin/main/index.html.haml#L87

And that property is defined for a belongs_to association here:
https://github.com/sferik/rails_admin/blob/5da7874fa606fd0a9627764482ff81833ef11921/lib/rails_admin/config/fields/types/belongs_to_association.rb#L15

The MongoID adapter does set adapter_supports_joins? to false, but as you can see in the code above, that doesn't cause sortable to return a falsey value, just a different kind of truthy value, so the view still offers to sort by that column. I'm not sure what the intention is, but it seems that sortable should return false for belongs_to associations on non-relational databases? Otherwise you get the sort link, and when you click on it, you end up here (the aforementioned RuntimeError):
https://github.com/sferik/rails_admin/blob/5da7874fa606fd0a9627764482ff81833ef11921/lib/rails_admin/adapters/mongoid.rb#L193

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