diff --git a/config/importmap.rb b/config/importmap.rb index 493c238..c633fd5 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -6,5 +6,5 @@ pin "@rails/actiontext", to: "actiontext.esm.js" pin_all_from Madmin::Engine.root.join("app/javascript/madmin/controllers"), under: "controllers", to: "madmin/controllers" -pin "tom-select", to: "https://unpkg.com/tom-select@2/dist/esm/tom-select.complete.js" -pin "tailwindcss-stimulus-components", to: "https://unpkg.com/tailwindcss-stimulus-components@5/dist/tailwindcss-stimulus-components.module.js" +pin "tom-select", to: "https://ga.jspm.io/npm:tom-select@2.4.1/dist/js/tom-select.complete.js" +pin "tailwindcss-stimulus-components", to: "https://ga.jspm.io/npm:tailwindcss-stimulus-components@6.1.2/dist/tailwindcss-stimulus-components.module.js" diff --git a/lib/madmin/fields/belongs_to.rb b/lib/madmin/fields/belongs_to.rb index 34612ac..bb10c46 100644 --- a/lib/madmin/fields/belongs_to.rb +++ b/lib/madmin/fields/belongs_to.rb @@ -2,12 +2,13 @@ module Madmin module Fields class BelongsTo < Field def options_for_select(record) - if (record = record.send(attribute_name)) - resource = Madmin.resource_for(record) - [[resource.display_name(record), record.id]] + records = if (record = record.send(attribute_name)) + [record] else - [] + associated_resource.model.first(25) end + + records.map { [Madmin.resource_for(_1).display_name(_1), _1.id] } end def to_param @@ -15,7 +16,11 @@ def to_param end def index_path - Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass).index_path(format: :json) + associated_resource.index_path(format: :json) + end + + def associated_resource + Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass) end end end