Kohana 3.1 ORM: How to make 'where … in' clause

后端 未结 2 883
执笔经年
执笔经年 2021-01-06 18:16

Thanks to Kohana\'s excellent documentation, I\'m having to resort to prostrate myself on SO. ;)

Hopefully this is really simple: I\'m trying to gather all stories w

相关标签:
2条回答
  • 2021-01-06 18:32

    Passing $story_ids as an array should work.

    $story_ids = array(12,56,99,213,319);
    $stories = ORM::factory('story')->where('id', 'IN', $story_ids)->find_all();
    

    What Kohana version do you use?

    0 讨论(0)
  • 2021-01-06 18:46

    Did you perhaps forget the ->select() ?

    Also, here are two ways outlined here to use the "IN" keyword:

    ORM::factory('table1')->select('mls_id')->where('mls_id', 'NOT IN', DB::Select('mls_id')->from('table2'))->find_all();
    ORM::factory('table1')->select('mls_id')->where('mls_id', 'NOT IN', DB::Expr('(SELECT mls_id FROM table2)'))->find_all();
    

    I typically use the DB::Expr method with what you're doing.

    0 讨论(0)
提交回复
热议问题