Last active
August 29, 2015 14:00
-
-
Save francisrod01/11151352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array | |
( | |
[Agencia] => Array | |
( | |
[joins] => Array | |
( | |
[0] => Array | |
( | |
[table] => cidades | |
[alias] => Cidade | |
[type] => left | |
[conditions] => Array | |
( | |
[Cidade.id] => AgenciaConfig.cidade_id | |
[Cidade.status] => 1 | |
) | |
) | |
[1] => Array | |
( | |
[table] => estados | |
[alias] => Estado | |
[type] => left | |
[conditions] => Array | |
( | |
[Estado.id] => Cidade.estado_id | |
[Estado.sigla] => SP | |
) | |
) | |
) | |
[conditions] => Array | |
( | |
[Agencia.status] => 1 | |
) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
$joins = array(); | |
$condtAg = array('Agencia.status' => 1); | |
if (!empty($this->request->data['Agency'])) : | |
$reqAg = $this->request->data['Agency']; | |
if (!empty($reqAg['state'])) { | |
$joins = array( | |
array( | |
'table' => 'cidades', | |
'alias' => 'Cidade', | |
'type' => 'left', | |
'conditions' => array( | |
'Cidade.id' => 'AgenciaConfig.cidade_id', | |
'Cidade.status' => 1 | |
) | |
), | |
array( | |
'table' => 'estados', | |
'alias' => 'Estado', | |
'type' => 'left', | |
'conditions' => array( | |
'Estado.id' => 'Cidade.estado_id', | |
'Estado.sigla' => $reqAg['state'] | |
) | |
) | |
); | |
} | |
if (!empty($reqAg['typeAgency'])) { | |
$condtAg .= "AgenciaTipo.id = {$reqAg['typeAgency']}"; | |
} | |
endif; | |
$this->paginate = array( | |
'Agencia' => array( | |
'joins' => $joins, | |
'conditions' => $condtAg | |
) | |
); | |
pr($this->paginate); | |
$agencies = $this->paginate('Agencia'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM agencias ag | |
INNER JOIN agencia_configs agc ON(agc.agencia_id = ag.id) | |
INNER JOIN cidades cd ON(cd.id = agc.cidade_id) | |
INNER JOIN estados est ON(est.id = cd.estado_id AND est.sigla = 'SP') | |
WHERE ag.status = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment