๋ ์ด์์ ํ
์ด๋ธ ์กฐ์ธ์ ๋ํ ๋ฌธ์ ๋ ์์ ๊ฐ ํ์๋์ง ์์ต๋๋ค. .join
ํธ์ถ ๋ง ์ฐ๊ฒฐํ๋ฉด ๊ฐ๋ฅํฉ๋๊น?
๋ค
knex์์ ์ฐ๊ฒฐ ์กฐ์ธ (๋ค์ค ํ ์ด๋ธ ์กฐ์ธ)์ด ๊ฐ๋ฅํฉ๋๋ค.
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 ์ด๋ป๊ฒ ์ด๊ฒ์ lool์ ๋งคํ ํ ์ ์์ต๋๊น?
{
"userId": 1,
...
"followers": [
{"userId": 2, ...},
...
]
}
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
knex์์ ์ฐ๊ฒฐ ์กฐ์ธ (๋ค์ค ํ ์ด๋ธ ์กฐ์ธ)์ด ๊ฐ๋ฅํฉ๋๋ค.
์๋ฅผ ๋ค๋ฉด :