0
我在形式代碼行<%= f.collection_select :owner_ids, Owner.order(:id), :id, :name, {}, {multiple: true} %>
返回大衆媒體形式的業主名單,但我需要在這個領域也包括公司,所以我可以在同樣的公司名單,導致一個大衆傳媒chanel可能由一個人或一家公司擁有。f.collection_select從軌道2中的2表3
Company.rb
class Company < ActiveRecord::Base
has_many :ownerships
has_many :massmedia, through: :ownerships
has_many :owners, through: :ownerships
end
Owner.rb
class Owner < ActiveRecord::Base
has_many :ownerships
has_many :massmedia, through: :ownerships
has_many :companies, through: :ownerships
end
Massmedium.rb
class Massmedium < ActiveRecord::Base
belongs_to :category
has_many :ownerships
has_many :owners, through: :ownerships
has_many :companies, through: :ownerships
end