We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

"in" clause in find() using a model relationship

OK so I read this: https://forum.phalcon.io/discussion/3469/modelfindcol-in-with-bind

and it appears that as of 2.0 Phalcon supports binding using an "in" clause. I have two models, model A and model B, which are related:

class A
{
    public function initialize(){
        parent::initialize();
        $this->hasMany("id","B","a_id",array("alias"=>"myA"));
        ...
    }

    $field1;
}

in a controller:

$result = A->getMyA(array("conditions"=>"field1 in (:param:)","bind"=>array("param"=>array(1,2,3))));

And I get this error: "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens"

What am I doing wrong?



145.0k
Accepted
answer

You just wrote it wrong:

https://blog.phalcon.io/post/phalcon-2-0-4-released

$result = A->getMyA(array("conditions"=>"field1 in {param:array})","bind"=>array("param"=>array(1,2,3))));