Page 308 - Nodejs 교과서 개정2판
P. 308
§ Ӓܿ / ҙ҅
ݽ؛ пп static associate ݫࢲ٘ী ֍णפ
models/user.js
...
static associate(db) {
db.User.hasMany(db.Comment, { foreignKey: 'commenter', sourceKey: 'id' });
}
};
models/comment.js
...
static associate(db) {
db.Comment.belongsTo(db.User, { foreignKey: 'commenter', targetKey: 'id' });
}
};
যڃ ݽ؛ী hasManyܳ ॳҊ যڃ ݽ؛ী belongsToܳ ॳח ഁтܾ Ѫੑפ ܲ ݽ؛ ࠁо ٜযоח
ప࠶ী belongsToܳ ࢎਊפ ઁীࢲח commenter ஸۢ ୶оغח $PNNFOU ݽ؛ী belongsToܳ ࢎ
ਊೞݶ ؾפ ࢎਊח ೠ ݺҊ Ӓী ࣘೠ ؆Ӗ ৈ۞ ѐ۽ ؆Ӗ ۽ী ࢎਊ commenter о ־ҳੋ
যঠ פ
द௬ۄૉח ਤীࢲ ೠ ۽ ݽ؛ р ҙ҅ܳ ঈ೧ࢲ $PNNFOU ݽ؛ী foreignKey ৻ې ః ੋ commente
r ஸۢਸ ୶оפ $PNNFOUFS ݽ؛ ৻ې ః ஸۢ commenterҊ 6TFS ݽ؛ id ஸۢਸ оܻఃҊ ण
פ