Skip to content

Commit

Permalink
Add collection to belongs to field
Browse files Browse the repository at this point in the history
  • Loading branch information
kaka-ruto committed Nov 20, 2024
1 parent 89ad662 commit cee338d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/madmin/fields/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ module Madmin
module Fields
class BelongsTo < Field
def options_for_select(record)
if (record = record.send(attribute_name))
if options[:collection].present?
collection = options[:collection].is_a?(Proc) ? options[:collection].call : options[:collection]
collection.map do |item|
resource = Madmin.resource_for(item)
[resource.display_name(item), item.id]
end
elsif (record = record.send(attribute_name))
resource = Madmin.resource_for(record)
[[resource.display_name(record), record.id]]
else
Expand Down

0 comments on commit cee338d

Please sign in to comment.