1

This is my SQL query that needs to be converted to cakephp type:

select `name` 
from `exams` 
left outer join `exam_results` on `exams`.id = `exam_results`.exam_id 
where `exam_results`.student_id = $sid

So how do I put it in controller and use find () etc. to query database.?

1 Answer 1

1

you can use table registry or model of the table. here i am using table registry-

 TableRegistry::get('exams')->find('all')
    ->where(['exam_results.student_id'=>$sid])
    ->leftJoin('exam_results', 'exam_results.exam_id = exams.id');

you need to add the name space use Cake\ORM\TableRegistry;

more info http://book.cakephp.org/3.0/en/orm/query-builder.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.