문제

When I do something like the following:

$site = ORM::factory('site')->where('name', '=', 'Test Site')->find();
$users = $site->users;
$deletedusers = $users->where('deleted', '=', '1')->find_all();
$nondeletedusers = $users->where('deleted', '=', '0')->find_all();

The contents of $deletedusers is correct, but the $nondeletedusers contains every non-deleted user, not just the ones in the loaded $site.

What am I doing wrong?

도움이 되었습니까?

해결책

Its because of find_all() and find() methods will reset your model state. For example, $user has a where('site_id', '=', <site_id>) condition (it was applied in the line#1 of your code). When you call find_all(), ORM resets all conditions, so $nondeletedusers works with empty model.

To avoid this behavior, you can try to clone $users, or retrieve all users ids from $user and add AND WHERE id IN <id list> condition.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top