module Madmin module Fields class HasMany < Field def options_for_select(record) if (records = record.send(attribute_name)) return [] unless records.first resource = Madmin.resource_for(records.first) records.map { |record| [resource.display_name(record), record.id] } else [] end end def to_param {"#{attribute_name.to_s.singularize}_ids": []} end def index_path Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass).index_path(format: :json) end end end end