cakephp - Multiple conditions in find all -


i'm tring enter conditions in find('all' on cake. that's logic:

traduction.traductions = username , traduction.status = 1 or 8     or,   traduction.check1 = username , traduction.status = 5 or 2      or,   traduction.check2 = username , traduction.status = 6 or 3     or,    trauduction.editions = username , traduction.status = 7 or 3 

if 1 of these condition right, display content

that's code far

    $conditions = array(                 'and' => array(                     array(                         'or' => array(                             array('traduction.traductions' => $this->session->read('auth.user.username')),                             array('traduction.status' => '1'),                             array('traduction.status' => '8')                         )                     ),                 'and' => array(                     array(                         'or' => array(                             array('traduction.check1' => $this->session->read('auth.user.username')),                             array('traduction.check1' => '5'),                             array('traduction.check1' => '2')                         )                     )                                        ),                 'and' => array(                     array(                         'or' => array(                             array('traduction.check2' => $this->session->read('auth.user.username')),                             array('traduction.check2' => '6'),                             array('traduction.check2' => '3')                         )                     )                                        ),                 'and' => array(                     array(                         'or' => array(                             array('traduction.edition' => $this->session->read('auth.user.username')),                             array('traduction.edition' => '7'),                             array('traduction.edition' => '4')                         )                     )                                        ),              )     );     $traduction = $this->traduction->find('all', array(         'conditions' => $conditions      )); 

but sadly seems don't work. here de sql dump

select `traduction`.`id`, `traduction`.`serie`, `traduction`.`issue`,     `traduction`.`page`, `traduction`.`writer`, `traduction`.`drawer`,  `traduction`.`release`, `traduction`.`traductions`, `traduction`.`check1`,  `traduction`.`check2`, `traduction`.`edition`, `traduction`.`user_name`,  `traduction`.`content`, `traduction`.`status`  `dcomicstrad`.`traductions`  `traduction` ((((`traduction`.`traductions` = 'drwhat')  or (`traduction`.`status` = 1)  or (`traduction`.`status` = 8)))  , (((`traduction`.`edition` = 'drwhat')  or (`traduction`.`edition` = '7')  or (`traduction`.`edition` = '4')))) 

someone can please me i'm bit lost these array x_x

you started off quite (with or cases), trapped in same old issue: never use array key twice (it overwrite previous one)!

$conditions = array(     'and' => array(),     'and' => array(),     'and' => array(), 

does that.

use this:

$conditions = array(      array(),      array(),      array(), 

you can remove 'and' => part cake default uses , connect array of arrays.

if want keep and, need make 1 lever deeper:

$conditions = array(     'and' => array(          array(),          array(),          array(), 

as sidenote: still cakephp talking about. containing @ least little bit of magic makes life easier. simplify query bit here. every or statement replace shorter array:

'or' => array(     array('traduction.traductions' => $this->session->read('auth.user.username')),     array('traduction.status' => '1'),     array('traduction.status' => '8') ) 

can become

'or' => array(     array('traduction.traductions' => $this->session->read('auth.user.username')),     array('traduction.status' => array('1', '8'), ) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -