Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Help me for how to Inner Join api in Phalcon

Please, help me for how to make inner join api correctly

> <br />
<b>Fatal error</b>:  Uncaught Phalcon\Mvc\Model\Exception: Syntax error, unexpected token (, near to '(PrfTeachers INNER JOIN EducationBackground ON PrfTeachers.id_teachers = EducationBackground.teacher_id) INNER JOIN RadiusLocations ON PrfTeachers.id_teachers = RadiusLocations.radius_id)', when parsing: SELECT prf_teachers.full_name, prf_teachers.birthday, prf_teachers.address, prf_teachers.city, prf_teachers.provinces, prf_teachers.districts, prf_teachers.villages, education_background.primary_school, education_background.junior_high_school, education_background.senior_high_school, education_background.diploma, education_background.s1, education_background.s2, education_background.s3, radius_locations.city, radius_locations.district FROM ((PrfTeachers INNER JOIN EducationBackground ON PrfTeachers.id_teachers = EducationBackground.teacher_id) INNER JOIN RadiusLocations ON PrfTeachers.id_teachers = RadiusLocations.radius_id) (632) in /var/www/html/guru-les/api_gurules/index.php:139
Stack trace:
#0 [internal function]: Phalcon\Mvc in
<b>/var/www/html/guru-les/api_gurules/index.php</b> on line
<b>139</b>
<br />


107.4k
Accepted
answer
edited May '17

Just use query builder. Best just post whole code which produces this error.

FROM ((PrfTeachers INNER JOIN EducationBackground ON PrfTeachers.id_teachers = EducationBackground.teacher_id)

Phalcon doesn't allow syntax like this, it's not implemented in PHQL Just do normal FROM like:

 FROM PrfTeachers INNER JOIN EducationBackground ON PrfTeachers.id_teachers = EducationBackground.teacher_id
edited May '17

how to use query bulder, I don't know use it, please teach me one example about make the Inner join api with query bulder

edited May '17

In your controller for example:

$result = $this->modelsManager->createBuilder()
    ->columns('*')
    ->from('PrfTeachers')
    ->innerJoin('EducationBackground', 'PrfTeachers.id_teachers = EducationBackground.teacher_id')
    ->innerJoin('RadiusLocations', 'PrfTeachers.id_teachers = RadiusLocations.radius_id')
    -getQuery()
    ->execute();

https://docs.phalconphp.com/en/3.0.1/reference/phql.html#creating-queries-using-the-query-builder

Oke Success, Thank you very much for helping me!