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.

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?



16.3k
Accepted
answer

You can give a look at the model documentation : http://docs.phalconphp.com/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 http://docs.phalconphp.com/en/latest/reference/phql.html :

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