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

Cannot list/sort models with namespaced table names #3620

Open
istrasci opened this issue Apr 12, 2023 · 0 comments
Open

Cannot list/sort models with namespaced table names #3620

istrasci opened this issue Apr 12, 2023 · 0 comments

Comments

@istrasci
Copy link

Describe the bug
Any models that has a namespaced table name of the form self.table_name = 'my_schema.my_table' cannot be listed/sorted. Gives the follow error:

ActiveRecord::UnknownAttributeReference - Query method called with non-attribute argument(s): "my_schema.my_table.my_primary_key asc"

Reproduction steps

  1. Create a model that has a namespaced table name (DBMS-dependent)
  2. Ensure it is being loaded by rails_admin
  3. Click on the model in the left nav to go to the list view.

Expected behavior
It should show the list view as normal, and further be able to sort.

Additional context

  • rails version: 6.1.7.3
  • rails_admin version: 3.1.2
  • rails_admin npm package version:
  • DBMS: Oracle 19c, using the adapter gem activerecord-oracle_enhanced-adapter-6.1.6
  • full stack trace (if there's an exception): rails_admin_stack_trace.txt

Workaround

I am able to at least bring up the list view by adding the following model config:

RailsAdmin.config do |config|
  config.model 'MyModel' do
    list do
      sort_by 'my_model.my_primary_key'
    end
  end
end

However, further sorting within the list view fails because it reverts back to trying to sort by using my_schema.my_table.column_to_sort.

Thoughts

I realize this ultimately boils down to an issue with rails (ActiveRecord::QueryMethods#reorder), but it would be nice if rails_admin could check the model's table name, and strip out the schema before listing/sorting.

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