I don't see any docs or examples on joining more than one table. Is this possible by just chaining .join
calls?
Yep
Chaining join (multiple tables join) in knex is possible.
var knex = require('./db')
knex('follow')
.join('users as u1', 'u1.id', 'follow.follower')
.join('users as u2', 'u2.id', 'follow.followee')
.select('u1.username as follower_name', 'u2.username as followee_name')
.then(follows => {
follows.map((follow) => {
console.log(follow.follower_name + " -> " + follow.followee_name);
})
})
@guanzhou-zhao how can this be mapped to lool like this...
{
"userId": 1,
...
"followers": [
{"userId": 2, ...},
...
]
}
Most helpful comment
Chaining join (multiple tables join) in knex is possible.
For example: