Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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

OK so I read this: https://forum.phalconphp.com/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?



114.4k
Accepted
answer

You just wrote it wrong:

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

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