'How can I join users and roles with Knex?

I am trying to join my users and roles tables. Users table has a role_id that references role id.

When I try to join, I get an error:

function getAll() {
  return db('users')
    .select('id', 'first_name', 'last_name', 'email', 'active', 'profile_photo', 'role_id')
    .leftJoin('roles', 'roles.id', 'users.role_id')
    .orderBy('id')
}
(node:66281) UnhandledPromiseRejectionWarning: error: select "id", "first_name", "last_name", "email", "active", "profile_photo", "role_id" from "users" left join "roles" on "roles"."id" = "users"."role_id" order by "id" asc - column reference "id" is ambiguous


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source