是否可以重复使用Kohana ORM查询行计数?

Ser*_*hiy 5 php kohana kohana-3 kohana-orm

所以我有我的疑问......

$records = ORM::factory('category');
Run Code Online (Sandbox Code Playgroud)

添加WHERE子句如此...

$records = $records->where('categoryid', 'LIKE', 'aa');
Run Code Online (Sandbox Code Playgroud)

抓住分页计数......

$count = $records->count_all();
Run Code Online (Sandbox Code Playgroud)

我的where子句被清除了......

SELECT `categories`.* FROM `categories` LIMIT 20 OFFSET 0
Run Code Online (Sandbox Code Playgroud)

用这条线注释掉了

//$count = $records->count_all();
Run Code Online (Sandbox Code Playgroud)

我的SQL看起来很好......

SELECT `categories`.* FROM `categories` WHERE `categoryid` LIKE 'aa' LIMIT 20 OFFSET 0
Run Code Online (Sandbox Code Playgroud)

是否可以按照我尝试的方式使用单个查询,还是必须进行两次重复的相同查询?一个用于计数,一个用于实际结果......

谢谢!

bia*_*ron 11

使用特殊reset(FALSE)电话:

$records = $records->where('categoryid', 'LIKE', 'aa');
$records->reset(FALSE); // !!!!
$count = $records->count_all();
$categories = $records->find_all();
Run Code Online (Sandbox Code Playgroud)