我正在尝试绑定 Company hasMany CompanyReview。下面是控制器中的代码:
public function review() {
$this->uses = array('Search', 'Company', 'CompanyReview');
$this->Company->bindModel(array(
'hasMany' => array(
'CompanyReview' => array(
'className' => 'CompanyReview',
'foreignKey' => 'company_id'
)
)
));
$this->CompanyReview->bindModel(
array(
'belongsTo'=>array(
'Company'=>array(
'className'=>'Company',
'foreignKey'=>'company_id'
)
)
)
);
if (!empty($this->data)) {
switch ($this->data['Search']['search_type']) {
case 'all':
$this->request->data['ReviewResults'] = $this->allReviews($this->data['Search']['search_query']);
break;
case 'company':
$this->request->data = $this->Company->find('all', array(
'conditions' => array(
'OR' => array(
'MATCH(Company.name) against ("' . $this->data['Search']['search_query'] . '" in boolean mode)',
'MATCH(CompanyReview.job_title) against ("' . $this->data['Search']['search_query'] . '" in boolean mode)'
)
)
));
break;
case 'interview':
$this->request->data['ReviewResults'] = $this->interviewReviews($this->data['Search']['search_query']);
break;
case 'salary':
$this->request->data['ReviewResults'] = $this->salaryReviews($this->data['Search']['search_query']);
break;
}
}
}
但我不断收到的错误是:数据库错误
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CompanyReview.job_title' in 'where clause'
SQL查询:SELECT Company.id, Company.name, Company.industry_id, Company.website, Company.created FROM terbang2.companies AS Company WHERE ((MATCH(Company.name) against ("air" in boolean mode)) OR (MATCH(CompanyReview.job_title) against ("air" in boolean mode)))
注意:如果要自定义此错误消息,请创建app/View/Errors/pdo_error.ctp
如果您注意到,sql 不包含 company_reviews 表。怎么会这样?请帮忙!。谢谢
哦,顺便说一句,company_reviews 表中有一个名为 job_title 的表行。