问题描述
我首先需要获得一个特定的ID,然后再按降序获得所有ID。这就是我所做的,但是当我取消注释该订单行时,它将不起作用,
$result = $this->Practicetestanswers->find('all',['contain' => ['Practicetestquestions' =>
['Practicetestconceptassignment' => ['Practicetestconcept','Practicetest']
]]])
->where(['Practicetestanswers.user_id' => $student_id,'Practicetestquestions.is_active' => 'y','Practicetest.is_active' => 'y'
])
->select([
'id' => 'Practicetest.id','test_code' => 'Practicetest.test_code','test_title' => 'Practicetest.test_title','time_taken' => 'SUM(Practicetestanswers.time_taken)',])
->group('Practicetest.id')
// ->order(["FIELD(Practicetest.id,'228')" => 'DESC']) //need like this
->order(["Practicetest.id" => 'DESC'])
->hydrate(false)
->toArray();
解决方法
只需根据条件用订单替换此行
->order(['FIELD(Practicetest.id,"228")'=> 'DESC',"Practicetest.id" => 'DESC' ])