我有案例模型。案例模型有 3 个字段用于实验室模型的 id。
案例模型
belongs_to :lab1, foreign_key: 'lab1', class_name: 'Lab', inverse_of: :lab1, conditions: {step1: true}
belongs_to :lab2, foreign_key: 'lab2', class_name: 'Lab', inverse_of: :lab2, conditions: {step2: true}
belongs_to :lab3, foreign_key: 'lab3', class_name: 'Lab', inverse_of: :lab3, conditions: {step3: true}
在实验室模型中
has_many :lab1, foreign_key: 'lab1', class_name: 'Case', inverse_of: :lab1
has_many :lab2, foreign_key: 'lab2', class_name: 'Case', inverse_of: :lab2
has_many :lab3, foreign_key: 'lab3', class_name: 'Case', inverse_of: :lab3
并且还形成以防万一
.lab_group
= f.association :lab1, label: false, input_html: {'data-placeholder'=> t('step.one')}
= f.input :lab1_delivered, label: t('case.done')
.lab_group
= f.association :lab2, label: false, input_html: {'data-placeholder'=> t('step.two')}
= f.input :lab2_delivered, label: t('case.done')
.lab_group
= f.association :lab3, label: false, input_html: {'data-placeholder'=> t('step.three')}
= f.input :lab3_delivered, label: t('case.done')
但是当我尝试保存它时,我有一个错误
Lab(#70207759169540) expected, got String(#70207716712320)
并请求参数
{"utf8"=>"✓",
"authenticity_token"=>"G0BWY6V6tkxRt81I0ZOxKXs8RD/7cdfbZfhVfRTmboo=",
"case"=>{"number"=>"123",
"doctor_id"=>"1",
"lab1"=>"1",
"lab1_delivered"=>"0",
"lab2"=>"2",
"lab2_delivered"=>"0",
"lab3"=>"2",
"lab3_delivered"=>"0",
"delivered"=>"0",
"patient"=>"",
"comment"=>"for example"},
"commit"=>"Save"}
和屏幕
我该如何解决?