我has_many :through
在某些模型之间建立了关联,这些模型决定了哪些数据集在某些仪表板上可见。
class Dashboard < ActiveRecord::Base
has_many :dashboard_datasets
has_many :datasets, :through => :dashboard_datasets
end
class DashboardDataaset < ActiveRecord::Base
belongs_to :dashboard
belongs_to :dataset
end
class Dataset < ActiveRecord::Base
has_many :dashboard_datasets
has_many :dashboards, :through => :dashboard_datasets
end
创建新的表单Dashboard
有一组简单的复选框,命名dataset_ids[]
允许您选择我希望在该仪表板上显示哪些预先存在的数据集。
class DashboardForm < Reform::Form
model: :dashboard
property :name
property :description
collection :dataset_ids
end
到目前为止,很简单...
但是,我现在希望向连接表添加一个额外的关联,以确定应该用于该给定仪表板上的该数据集的“布局”。即网格、表格、列表。ETC
class Layout < ActiveRecord::Base
has_many :dashboard_datasets
end
class DashboardDataaset < ActiveRecord::Base
belongs_to :dashboard
belongs_to :dataset
belongs_to :layout
end
我现在想调整我的仪表板表单,以便除了复选框之外,对于选中的每个数据集复选框,都有一个选择框供我选择要在此给定关联上使用的布局。
我从哪里开始?扩展collection
表单对象以更丰富并包含更多信息?
非常感谢任何建议。