を挿入します。ネストされたレコードは、私たちは以下のようにデータベーススキーマを持ってknex.js
students
テーブル
| id |名前|アドレス|
学生が複数の教育歴を持っています。
education_histories
テーブル
| id |度|大学| student_id |
{
"name" :"Ram Neupane",
"address": "Kathmandu, Bagmati",
"education_histories": [
{
"degree": "I.Sc.",
"university": "Tribhuvan University"
}, {
"degree": "BE",
"university": "Tribhuvan University"
}
]
}
私はNode.jsとKnex.jsに新しいです:#student_id
たちは以下のように、クライアント側からJSON構造を取得し、外部キーポインティング学生テーブル
です。私はstudent
を挿入し、education history
を入れて、データベースにbluebird約束をKnexで使用したいと思っています。どうすればこの問題を解決できますか?
私は約束以下で試してみました:
function create (jsonParam) {
return new Promise(function (resolve, reject) {
knex('students')
.insert({name: jsonParam.name, address: jsonParam.address})
.returning('id')
.then(function (response) {
# Here, I want to insert record to education_histories table
})
.catch(function (err) {
reject(err);
});
})
}