CakeDC / search

Search Plugin for CakePHP
http://cakedc.com
Other
355 stars 169 forks source link

[question] alternate between 'OR' <-> 'AND' Condition(cakephp3) #193

Closed flashios09 closed 8 years ago

flashios09 commented 9 years ago

Hi, Thanks @deizel (and all the CakeDC team) for this awesome cakephp plugin :+1: Sorry for my bad english Let's say that i have two actions in my controller, the first is filter and the second is enhancedSearch. I have two field in my table min and max. That's my Search plugin config:

public $filterArgs = [
    'min' => [
        'type' => 'value'
    ],
    'max' => [
        'type' => 'value'
    ]
];

By default this config will generate an AND condition(exp. ... WHERE min=5 AND max=10), i need an AND condition in the filter action but i need an OR condition(exp. ... WHERE min=5 OR max=10) in the enhancedSearch action. What i have to do ?

Thanks

dereuromark commented 9 years ago

You should probably make a custom condition then as documented.

kostalihas commented 9 years ago

hi I want use connector '+' for AND ',' for OR but its not working in my code: public $hasAndBelongsToMany = array( 'Competence' => array( 'with' => 'CompetencesUser', 'className' => 'Competence', 'joinTable' => 'competences_users', 'foreignKey' => 'user_id', 'associationForeignKey' => 'competence_id', 'unique' => 'keepExisting', ) );

public $filterArgs = array( 'username' => array( 'type' => 'value' ), 'nom' => array( 'type' => 'like' ), 'prenom' => array( 'type' => 'like' ), 'email' => array( 'type' => 'value' ), 'competences' => array( 'type' => 'subquery', 'method' => 'findByCompetences', 'field' => 'User.id', 'before' => true ),

        'search_with_connectors' => array(
    'type' => 'like',
    'field' => 'Competence.competence',
    'connectorAnd' => '+', 'connectorOr' => ','

) ); public function findByCompetences($data = array()) {

    $this->CompetencesUser->Behaviors->attach('Containable', array(
            'autoFields' => false
        )
    );

    $this->CompetencesUser->Behaviors->attach('Search.Searchable');

    $query = $this->CompetencesUser->getQuery('all', array(
        'conditions' =>
    array(

    'Competence.competence' => $data['competences'],

    ),
    'fields' => array(
            'user_id'
        ),
        'contain' => array(
            'Competence'
       )

    ));
     return $query;
}
antoniovassell commented 9 years ago

Guess we can close this and focus on #204

Megslalk commented 8 years ago

Hi, Closing this issue, please open a new one if still needed.