How to use `Models::find`?

$submodules = Modules::find( array( 'moduleid in (:mods:) and parentid = :parentid:', 'bind' => array( 'mods' => '1,2', 'parentid' => 1 ), 'bindtype' => array( 'mods' => Column::BINDPARAMSTR, 'parentid' => Column::BINDPARAMINT ) ) ); I hope the sql that is "select * from modules where moduleid in (1,2) and parentid = 1" but result is not correct.

help plz.



83.4k

Escaping :mods: will produce '1,2' therefore: select * from modules where moduleid in ('1,2') and parentid = 1

You need to use a bound parameter for every value in the "in":

$submodules = Modules::find(array(
    'moduleid in (:firstMod:, :secondMod:) and parentid = :parentId:',
    'bind' => array(       
        'firstMod' => 1,
        'secondMod' => 2,
        'parentId' => 1
    )
));


8.0k

thanks,but i means the SQL sames like moduleid in ( $variable ) and current variable may be come from the form's post or get.

$variable = $this->request->getPost('variable');

$submodules = Modules::find(array( 'moduleid in (:variable:) and parentid = :parentId:', 'bind' => array(
'variable' => $variable, 'parentId' => 1 ) ));