I inherited this Kohana project and have little experience with it and ORM.
Table structure is like this:
ROLES TABLE
id
name
ROLES_USERS TABLE
role_id
user_id
USERS TABLE
id
email
password
last_login
The thing is, I need to get users sorted by whether they have a certain role (login in this case) but have no idea how to do that with ORM.
Current query is:
$users = ORM::factory('user')
->limit($pagination->items_per_page)
->offset($pagination->offset)
->order_by('last_login', 'DESC')
->find_all();
and then when outputting it’s printed like this:
$row['status'][] = ($user->has('roles', ORM::factory('role', array('name' => 'login')))
? '<span class="green">Active</span>'
: '<span class="red">Blocked</span>');
So the question would be how to alter the query to be able to sort by whether users are allowed to login or not.
I hope you don’t have 2000 roles, but active users should come first using this query