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

How to load several Models with an array of id's

Hi

I've got an array with ids I want to load. I tried the following but the result was always the product with the first id from $productstoload:

//$productstoload is the array with the ids

$products = Product::find([
                [
                    '$or' => $productstoload
                ]
            ]);

Thank you for your help!



32.3k
Accepted
answer
edited Jul '18

Hi @campinony you have to use

$products = Product::find([
    'conditions' => 'id in ({ids:array-int})'
    'bind' => [
        'ids' => $productstoload
    ]
]);

Good luck



1.1k

Thanks a lot!