所以这是一个示例类
class Company < ActiveRecord::Base
has_many :investments
has_many :vc_firms, through: :investments, source: :investor, source_type: 'VentureFirm'
has_many :angels, through: :investments, source: :investor, source_type: 'Person'
end
@company.angels 和 @company.vc_firms 按预期工作。但是我如何拥有由两种来源类型组成的@company.investors?这适用于 Investments 表的 Investor 列上的所有多态性吗?或者可能是使用范围合并所有 source_type 的一种方式?
投资模型如下:
class Investment < ActiveRecord::Base
belongs_to :investor, polymorphic: true
belongs_to :company
validates :funding_series, presence: true #, uniqueness: {scope: :company}
validates :funded_year, presence: true, numericality: true
end
天使通过 Person 模型关联
class Person < ActiveRecord::Base
has_many :investments, as: :investor
end
相关金融组织模型协会:
class FinancialOrganization < ActiveRecord::Base
has_many :investments, as: :investor
has_many :companies, through: :investments
end