Hello,
I’m trying to create the following query in Yii:
SELECT i.id_indicador, oi.id_objetivo
FROM indicador i
LEFT JOIN objetivo_indicador oi ON (i.id_indicador = oi.id_indicador)
WHERE i.id_indicador NOT IN( SELECT id_indicador FROM `objetivo_indicador` WHERE `id_objetivo` = 4 )
… I tried as follows:
$subconsulta = ObjetivoIndicador::model()->findAll(array(
'select'=>'id_indicador',
'condition'=>'id_objetivo=:objBuscado',
'params'=>array(':objBuscado'=>4)
));
$consulta = Indicador::model()->findAll(array(
'select'=>'t.id_indicador, oi.id_objetivo',
'join'=>'LEFT JOIN objetivo_indicador oi ON (t.id_indicador = oi.id_indicador)',
'condition'=>'t.id_indicador NOT IN :subConsulta',
'params'=>array(':subConsulta'=>$subconsulta)
));
… but generates the following error: "[color="#8B0000"]PHP Error - Array to string conversion[/color] "
…the basic structure of the tables is this:
//
// (t) (i)
// --------------------- --------------
// | objetivo_indicador | | indicador |
// |---------------------| |--------------|
// | id_objetivo |>------| id_indicador |
// | id_indicador | | nombre |
// --------------------- ---------------
// ______________________________________________________________________________
//
// objetivo indicador | indicador
// 4 2 | 1
// 4 3 | 2
// 5 1 | 3
// | 4
// |
…the idea of query is [color="#0000FF"]show the indicators that are not associated with objective 4[/color]
What is wrong in the syntax of the query? How I can create this query in Yii?
I thank you in advance for your ideas and collaboration …!