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 implement a where in statement in a model?

It seems there is only way to found a where in statement.

<?php $robots = Robots::find("type IN ('virtual', 'mechanical')");

Is there any more graceful way to do this?



21.8k
Accepted
answer

You can give a look at the model documentation : https://docs.phalcon.io/en/latest/reference/models.html

<?php

$robots = Robots::query()
    ->where("type = :type:")
    ->andWhere("type IN ('virtual', 'mechanical')")
    ->bind(array("type" => "mechanical"))
    ->order("name")
    ->execute();

You may also use phql https://docs.phalcon.io/en/latest/reference/phql.html :

<?php
$phql = "SELECT * FROM Cars WHERE Cars.id IN (120, 121, 122)";