Php 如何使用Kohana ORM选择where-if-in?

Php 如何使用Kohana ORM选择where-if-in?,php,mysql,orm,kohana,Php,Mysql,Orm,Kohana,我试图在Kohana ORM中实现这一点,但不知道如何实现: SELECT t.name FROM t WHERE IF(t.s1_id = 1, t.s2_id IN (2,3,4), t.s1_id IN (2,3,4)) 试试这个: SELECT t.name FROM t WHERE (t.s1_id = 1 and t.s2_id IN (2,3,4) ) or ( t.s1_id IN (2,3,4) ) 我自己还没有用过这个,但是用floww的转换,这个应该可以 $model

我试图在Kohana ORM中实现这一点,但不知道如何实现:

SELECT t.name
FROM t
WHERE IF(t.s1_id = 1, t.s2_id IN (2,3,4), t.s1_id IN (2,3,4))
试试这个:

SELECT t.name FROM t WHERE (t.s1_id = 1 and t.s2_id IN (2,3,4) ) or ( t.s1_id IN (2,3,4) )

我自己还没有用过这个,但是用floww的转换,这个应该可以

$model = ORM::factory('t')->and_where_open()
    ->where('s1_id', '=', '1')
    ->where('s2_id', 'IN', array(2,3,4))
    ->and_where_close()
    ->or_where('s1_id', 'IN', array(2, 3, 4));
如果您希望得到一个结果,请立即使用
$model->find()
,您可以通过
$model->name
访问该名称

如果希望得到多个结果,请使用
$model->find_all()
并对其进行迭代,获得所有的
->name
s


正如您在中所看到的,ORM不支持
IF
语句。如果你不想要一个硬编码的解决方案,我认为你必须自己添加这个功能