Don*_*ulo 2 kohana-3 kohana-orm
感谢Kohana的出色文档,我不得不求助于自己.;)
希望这很简单:我正在尝试收集属于某组ID的所有故事.我的代码如下:
$story_ids = '(12,56,99,213,319)';
$stories = ORM::factory('story')->where('id', 'IN', $story_ids)->find_all();
Run Code Online (Sandbox Code Playgroud)
但是,这显然不起作用.我收到MySQL错误,因为单引号被放在$story_ids查询中的字符串周围.
编辑:我也试过传递$story_ids作为一个数组,但后来我得到一个"500内部服务器错误"
有可能做我要问的事吗?
提前致谢.
将$ story_ids作为数组传递应该可行.
$story_ids = array(12,56,99,213,319);
$stories = ORM::factory('story')->where('id', 'IN', $story_ids)->find_all();
Run Code Online (Sandbox Code Playgroud)
你用什么Kohana版本?
你有没有忘记- > select() ?
此外,这里有列出两种方法在这里用"IN"的文章:
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();
Run Code Online (Sandbox Code Playgroud)
我通常使用DB :: Expr方法来处理你正在做的事情.