Ruby on rails 要按特定属性选择的Rails where子句

Ruby on rails 要按特定属性选择的Rails where子句,ruby-on-rails,Ruby On Rails,我有以下疑问: 我有以下型号: 2.1.5 :025 > OnlineCourseRegistration.last => #<OnlineCourseRegistration id: 14392, cart_id: 15177, user_id: 7133, course_class_id: 681, created_at: "2017-10-29 23:28:45", updated_at: "2017-10-30 20:18:53", exam_attempts: 0,

我有以下疑问:

我有以下型号:

2.1.5 :025 > OnlineCourseRegistration.last
 => #<OnlineCourseRegistration id: 14392, cart_id: 15177, user_id: 7133, course_class_id: 681, created_at: "2017-10-29 23:28:45", updated_at: "2017-10-30 20:18:53", exam_attempts: 0, exam_completed_at: nil, evaluation_completed_at: nil, status: "Active", score: "", add_extension: false, retest_cart_id: nil, retest_purchased_at: nil>
可能会返回同一用户id的多条记录。如果是这种情况,我只想返回最后一条记录…或者该用户的最新记录:exam_completed_

对于上下文,这里是整个循环:


registrations=OnlineCourseRegistration.where(课程号:123)。where(状态:“已完成”)。where(“分数以下是我的想法:


registrations=OnlineCourseRegistration.where(课程类别id:842)。where(状态:“已完成”)。where(“分数以下是我的想法:


registrations=OnlineCourseRegistration.where(课程类别id:842).where(状态:“已完成”).where(“分数”)您可以附加
顺序(考试已完成地址::desc)。选择('distinct on(email)name')
或在电子邮件数组中调用
.uniq
。您可以附加
顺序(考试已完成地址::desc)。选择('distinct on(email)name')
或只需在电子邮件数组中调用
.uniq
。。。
registrations = OnlineCourseRegistration.where(course_class_id: 123).where(status: "Completed").where("score >= ?", 80)