How can i used the sort order in different table with join conditions ? In Questions table ques_order column and Client-question table ques_order how can i get the query returned with different order condition. is that that possible the sql query.Please any solution for the query.
Please post the query you are using.
$questions = $this->Questions
->find()
->contain(['QuestionTypes'=>['fields'=>['id', 'name']] ])
->contain(['ClientQuestions'=>['fields'=>['id', 'client_id','question_id','is_compulsory','ques_order'], 'conditions'=>['ClientQuestions.client_id IN'=>$contractor_clients]] ])
->contain(['ClientQuestions.Clients'=>['fields'=>['id', 'company_name']]])
->contain(['ContractorAnswers'=>['conditions'=>['contractor_id'=>$contractor_id, 'year IS'=>$year]] ])
->where(['active'=>true, 'category_id'=>$category_id])
->order(['ques_order'=>'ASC','Questions.id'=>'ASC'])
->all();
Here is my code
From your question, it seems like you have a ques_order
column in both Questions and ClientQuestions tables? Which one are you trying to reference in the sort order? You should just be able to put that table name before it, like you have already done with Questions.id
.
This may depend on the associations between tables, though. HasMany relations are by default loaded with a separate query, for example, meaning that they can’t be included in the sort order. But if you’re wanting to sort on that, the question needs to explain what you want the final data structure to look like.
Your right i trying to do both sort in single query,It’s not possible, because their are different condition working these sort not work same time on a single query.`