Kohana 3 ORM find_all () returns all rows no matter where the sentence

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 happens, I am returning ALL of my users from the database, and not just those with email_notifications enabled. The funny thing is that the return value of $total is the exact result number of this query.

I'm so stupid, I have no idea what the problem is. If anyone could shed some light, I would really appreciate it.

Thanks,
Brian

+4
source share
1 answer

Calling count_all() will reset the conditions of your model. Try using reset(FALSE) to avoid this:

  $user = ORM::factory('user'); $user = $user->where('email_notifications', '=', 1); $user->reset(FALSE); $total = $user->count_all(); $users = $user->find_all(); 
+9
source

Source: https://habr.com/ru/post/1344094/


All Articles