Kohana 3 ORM find_all() 返回所有行,无论 where 子句如何
我有一个简单的 users
表,我想查找 email_notifications
= 1 的所有用户。
逻辑表明以下操作应该有效:
class Controller_Test extends Controller {
public function action_index()
{
$user = ORM::factory('user');
$user = $user->where('email_notifications', '=', 1);
$total = $user->count_all();
$users = $user->find_all();
echo $total." records found.<br/>";
foreach ($users as $v)
{
echo $v->id;
echo $v->first_name;
echo $v->last_name;
echo $v->email;
}
}
}
然而,发生的情况是,我正在从数据库中恢复所有用户,而不仅仅是那些打开了 email_notifications 的用户。有趣的是,返回的$total
值是这次查询的准确数字结果。
我很困惑,我不知道问题出在哪里。如果有人能提供一些线索,我将非常感激。
谢谢,
布莱恩
I have one simple users
table, and I want to find all users where email_notifications
= 1.
Logic dictates that the following should work:
class Controller_Test extends Controller {
public function action_index()
{
$user = ORM::factory('user');
$user = $user->where('email_notifications', '=', 1);
$total = $user->count_all();
$users = $user->find_all();
echo $total." records found.<br/>";
foreach ($users as $v)
{
echo $v->id;
echo $v->first_name;
echo $v->last_name;
echo $v->email;
}
}
}
However, what's happening is that I am getting ALL of my users back from the DB, not just the ones with email_notifications turned on. The funny thing is, the $total
value returned is the accurate number result of this query.
I am so stumped, I have no idea what the problem is here. If anyone could shed some light, I'd really appreciate it.
Thanks,
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
count_all()
将重置您的模型条件。尝试使用reset(FALSE)
来避免这种情况:Calling
count_all()
will reset your model conditions. Try to usereset(FALSE)
to avoid this: