I have a table jobs
whose structure is similar to below :
id desc
1 Job Description
And a table job_categories
to save the categories of the jobs:
id job_id category_id
1 1 2
2 1 3
3 1 4
So to get the categories gor the job with id 1
, in JobsController.php
, I wrote:
$similar_conditions['JobCategory.job_id'] = 1;
$similar_jobs = $this->Job->find('all',array('conditions' => $similar_conditions));
And my job model Job.php
is:
class Job extends AppModel {
var $name = 'Job';
var $belongsTo = array('Qualification');
var $hasMany = array('JobCategory');
}
But it is showing an error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'JobCategory.job_id' in 'where clause'
. The query it is generating is:
SQL Query: SELECT
Job
.id
,Job
.job_title
,Job
.job_description
,Job
.job_skills
,Job
.contact_number
,Job
.contact_email
,Job
.qualification_id
,Job
.experience
,Job
.categories
,Job
.remarks
,Job
.support_image
,Job
.freshers_apply
,Job
.added_on
,Job
.status
,Qualification
.id
,Qualification
.name
FROMcakead
.jobs
ASJob
LEFT JOINcakead
.qualifications
ASQualification
ON (Job
.qualification_id
=Qualification
.id
) WHEREJobCategory
.job_id
= 1
Why my table job_categories is not joining ?