【发布时间】:2019-02-11 07:41:30
【问题描述】:
Class Doctor
has_many :patients
end
Class Patient
belongs_to :doctor
has_many :historics
end
Class Historic
belongs_to :patient
end
我有这样的结构。当我是一名医生时,我想获取所有患者的列表,但只显示每个患者的最后一个历史记录。
到目前为止,我无法找到如何做到这一点。我应该创建这样的东西吗?
Class Doctor
has_many :patients_with_one_historic, class_name: 'Historic', :through => :patient, :limit => 1
end
但在这种情况下,这将返回患者的历史模型而不是具有一个历史的患者模型?!
我使用的是 Rails 5.1.5
【问题讨论】:
-
定义 2 关联,正如我在对
patient- historic关系的回答中提供的那样
标签: ruby-on-rails ruby-on-rails-5 model-associations