我这样的三个模型具有多态关联:
主要型号:
# == Schema Information
#
# Table name: packages
#
# id :integer not null, primary key
# name :string
# price :money
# plan_id :integer
# plan_type :string
# active :boolean default(FALSE)
# order :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Package < ActiveRecord::Base
belongs_to :plan, polymorphic: true
monetize :price
end
一个孩子:
# == Schema Information
#
# Table name: timepackages
#
# id :integer not null, primary key
# months :integer
# downloads :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Timepackage < ActiveRecord::Base
has_one :package, as: :plan, dependent: :destroy
end
我需要获取Timepackages
值为months
的所有{{1}}。我该怎么做?
答案 0 :(得分:1)
Timepackage.where(:months => 1)
我不知道您问题标题中提到的多态关系是如何进入实际问题中列出的要求的。