0
我有一些問題從多個表中搜索。我有一個卡片模型的關鍵字搜索設置工作正常,我還希望關鍵字查看具有card_id的外鍵的聯繫人模型。我似乎無法解決如何解決這個問題。cakephp cakedc搜索插件 - 多表/多個查詢搜索
的點一下/有問題的findByContacts
功能:
array('Contact.street_suburb' => 'contacts',
'type' => 'subquery',
'method' => 'findByContacts',
'field' => 'Card.id'),
我已經開始嘗試剛剛得到的郊區進行搜索,但我非常希望任何接觸模型中的字段的出現在卡片搜索上。
謝謝!
我的卡型號代碼如下:
public $filterArgs = array(
array('name' => 'keyword', 'type' => 'query', 'method' => 'filterQuery'),
);
public $hasAndBelongsToMany = array('Contact' => array('with' => 'Contact'));
public function filterQuery($data = array()) {
if(empty($data['keyword'])) { // keyword is the name of my search field
return array();
}
$query = '%'.$data['keyword'].'%';
return array(
'OR' => array(
array('Card.name LIKE' => $query),
array('Property.name LIKE' => $query),
array('Building.name LIKE' => $query),
array('Stage.name LIKE' => $query),
array('Contact.street_suburb' => 'contacts', 'type' => 'subquery', 'method' => 'findByContacts', 'field' => 'Card.id'),
)
);
} // END SEARCH
// FIND BY CONACTS - PART OF SEARCH
// ------------------------------------------------------------------------------------>
public function findByContacts($data = array()) {
$this->Contact->Behaviors->attach('Containable', array('autoFields' => false));
$this->Contact->Behaviors->attach('Search.Searchable');
$query = $this->Contact->getQuery('all', array(
'conditions' => array('Contact.street_suburb' => $data['contacts']),
'fields' => array('foreign_key'),
'contain' => array('Contact')
));
return $query;
}
我想你錯過了幾件事,但你可以定義不工作?什麼是不工作?它是否正確地搜索卡片?它是否正確地搜索聯繫人?它至少做了一個查詢嗎?或根本就沒有做任何事情? – api55
謝謝,我在上面提到的錯誤是: 警告(512):SQL錯誤:1054:'where子句'中的未知列'Contact.street_suburb'[CORE/cake/libs/model/datasources/dbo_source .php,line 684] 我想這意味着聯繫人和卡模型沒有正確鏈接... – sluggerdog
當我嘗試搜索多個表時,出現類似錯誤。 –