我有表字段:
t.string "name"
t.integer "id_survey"
t.integer "id_participant"
我在数据库中有以下实例:
Field1= ["id_participant" => 1, "id_survey" => 1, "name" => "p1_c1_exams1"]
Field2= ["id_participant" => 1, "id_survey" => 1, "name" => "p1_c1_exams2"]
Field3= ["id_participant" => 1, "id_survey" => 1, "name" => "p1_c1_examination1"]
Field4= ["id_participant" => 1, "id_survey" => 1, "name" => "p1_c1_examination2"]
我有一个变量:
nameStep = "p1_c1_exams"
我想找到名称为“....exams”和更大数字的实例。
我试过了
lastField = Field.find{|f| f['id_participant']==1 and f['id_survey']==1 and f['name'].include? nameStep}['name']
但它在数据库“p1_c1_exams1”而不是“p1_c1_exams2”中找到第一个实例
然后我尝试了:
lastField = Field.last{|f| f['id_participant']==1 and f['id_survey']==1 and f['name'].include? nameStep}['name']
但它在数据库“p1_c1_examination2”而不是“p1_c1_exams2”中找到最后一个实例
我该如何编写查询?