如何使用cakedc/search插件通过一个搜索栏在3个不同的表中进行搜索? [英] how to use cakedc/search plugin for searching across 3 different tables with 1 search bar?
问题描述
我正在使用CakePHP2.4和搜索插件 https://github.com/CakeDC/search
I am using CakePHP2.4 and the search plugin https://github.com/CakeDC/search
我有以下内容
Employee hasOne EmployeeProfile
Employee hasMany Qualification
所以我只有一个搜索栏.
So I have a single search bar.
搜索栏将使用LIKE在以下字段中进行搜索
the search bar will search using LIKE through the following fields
Employee.name
EmployeeProfile.email
Qualification.title
如何为该搜索配置模型 Employee-> filterArgs
?
how do I configure the model Employee->filterArgs
for this search?
这是原始问题的交叉发布此处
This is a cross-posting of the original issue here
推荐答案
我想对此进行扩展,因为我试图在hasMany关系上进行搜索已有几个小时,但找不到任何东西.马克提到了针对hasMany关系(Qualification)的自定义bindModel(作为hasOne)".这是完成的过程:
I'd like to expand on this as I've been trying to setup a search on a hasMany relationship for a few hours and couldn't find anything. Mark mentionned "custom bindModel (as hasOne) for hasMany relationship (Qualification)". Here's how it's done :
$this->Employee->bindModel(array(
'hasOne' => array(
'Qualification' => array(
'foreignKey' => false,
'conditions' => array('Employee.id = Qualification.employee_id')
)
)
), false);
只需将其绑定到分页之前,然后在filterArgs的字段列表中添加Qualification.title
Just bind it before your paginate and add Qualification.title in your field list in your filterArgs
这篇关于如何使用cakedc/search插件通过一个搜索栏在3个不同的表中进行搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!