'Rails Admin Polymorphic association model in one field
I have these four classes which are combined with polymorphic association. Podcast and Article use adapter_inhouse_banner for the inhouse_id and inhouse_type.
adapter_inhouse_banner also keeps an inhouse_banner_id column which has a foreign key connection with the id on inhouse_banner
For context: The idea behind inhouse banners is to choose articles and podcasts to be displayed in a seperate pages with ids called inhouse banners
class Podcast < ApplicationRecord
has_many :adapter_inhouse_banners, as: :inhouse
end
class Article < ApplicationRecord
has_many :adapter_inhouse_banners, as: :inhouse
end
class AdapterInhouseBanner < ApplicationRecord
belongs_to :inhouse_banner
belongs_to :inhouse, polymorphic: true
end
class InhouseBanner < ApplicationRecord
has_many :adapter_inhouse_banner
has_many :articles, through: :adapter_inhouse_banner, source: :inhouse, source_type: 'Article'
has_many :podcasts, through: :adapter_inhouse_banner, source: :inhouse, source_type: 'Podcast'
end
I currently have my rails configuration setup as such:
config.model InhouseBanner do
edit do
field :title
field :articles
field :podcasts
end
end
It looks like this
I want to combine the articles and podcasts in one field make it look like this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
