0

I am using CakePHP2.4 and the search plugin https://github.com/CakeDC/search

I have the following

Employee hasOne EmployeeProfile 
Employee hasMany Qualification

So I have a single search bar.

the search bar will search using LIKE through the following fields

Employee.name
EmployeeProfile.email
Qualification.title

how do I configure the model Employee->filterArgs for this search?

This is a cross-posting of the original issue here

ndm
  • 59,784
  • 9
  • 71
  • 110
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
  • I'd say: custom bindModel (as hasOne) for hasMany relationship (Qualification) and `'field' => array(all, my, fields)` - or paginating the hasMany records. – mark Jul 28 '13 at 15:06

2 Answers2

0

The documentation includes an example.

'username' => array('type' => 'like', 'field' => array('User.username', 'UserInfo.first_name')),

You just have to make sure the models you're calling are available in your find() call. In the example the find will do a like on the users table username and on the user_infos first_name field at the same time.

floriank
  • 25,546
  • 9
  • 42
  • 66
0

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);

Just bind it before your paginate and add Qualification.title in your field list in your filterArgs

Dominic Horbas
  • 132
  • 2
  • 11