嵌入式类在另一个嵌入式类中

时间:2015-01-07 17:54:27

标签: ruby mongodb ruby-on-rails-4

人。我正在创建一个患者可能会接受多种治疗的结构,治疗方法每个只能有一个病例。如下

class Patient
  include Mongoid::Document
  include Mongoid::Slug
  include Mongoid::Paperclip
  include Mongoid::Timestamps
  include SimpleEnum::Mongoid

  embeds_many :addresses
  embeds_many :treatments

end

class Treatment
  include Mongoid::Document
  include Mongoid::Timestamps

  embedded_in :patient, inverse_of: :treatments

  embeds_one :case_history
  embeds_one :physical_examination
  embeds_one :diagnostic_hypothesis
  embeds_one :evolution
  embeds_one :prescription
  embeds_one :certificate
  embeds_many :attachments
end


class CaseHistory
  include Mongoid::Document
  include Mongoid::Timestamps

  embedded_in :treatments, inverse_of: :case_history

  field :main_complaint
  field :history

end

我尝试按如下方式创建一个case_history对象:

patient = Patient.find(params[:patient_id])
treatment = patient.treatments.find(params[:treatment_id])
case_history = patient.treatments.treatment.case_history.create(case_history_params)

但它不起作用

可能出现什么问题?

0 个答案:

没有答案