我有以下2个模型:
父模型:
class Babysitter < ApplicationRecord
has_many :jobs
has_many :babysitters, through: :jobs
保姆型号:
class Babysitter < ApplicationRecord
has_many :jobs
has_many :parents, through: :jobs
他们有一个来自 Job 模型的 has_many through 关系:
Model Job:
class Job < ApplicationRecord
belongs_to :Babysitter, :touch => true
belongs_to :Parent
end
我现在想打电话babysitter.parents
,但让每个父母也包括属性薪水(Jobs
表中的一个属性)。
这可能吗?
我试过了:
babysitter.parents.includes(:jobs.salary)
此外,是否可以将结果包含在 fastJsonApi 中?
parents_including_salary = babysitter.parents.includes(:jobs.salary)
options = { 包括:[:babysitter, :'parents_including_salary']} json = Api::CampaignReportSerializer.new(otherData, options).serialized_json