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

selected_list will not link to models without an "id" column #372

Open
schwern opened this issue Aug 30, 2021 · 0 comments
Open

selected_list will not link to models without an "id" column #372

schwern opened this issue Aug 30, 2021 · 0 comments

Comments

@schwern
Copy link

schwern commented Aug 30, 2021

I've have a State table where the primary key is not :id, it is :abbr. It also has a :name column.

# db/migrate/create_states.rb
class CreateStates < ActiveRecord::Migration[6.1]
  def change
    create_table :states, id: false, bulk: true do |t|
      t.primary_key :abbr, :string, limit: 2
      t.string :name, null: false
      t.timestamps
    end
  end
end

# app/model/state.rb
class State < ApplicationRecord
end

# app/admin/states.rb
ActiveAdmin.register State do
  config.sort_order = 'abbr_asc'
end

I've made a selected list for them.

            f.input :state_ids,
              label: "States",
              as: :selected_list,
              order_by: "abbr_asc",
              fields: [:abbr, :name],
              wrapper_html: { title: "Restrict to these US states only." }

The searching works fine, but I cannot click on the shown states. There are no Javascript errors in console.

If I add a fake id column it works.

# app/model/state.rb
class State < ApplicationRecord
  attribute :id, type: :string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant