Page 315 - Nodejs 교과서 개정2판
P. 315
where: { id: 2 },
});
destroy ݫࢲ٘۽ ઁפ where ২࣌ী ઑѤٜਸ णפ
ҙ҅ ௪ܻ
findOneա findAll ݫࢲ٘ܳ ഐೡ ٸ ۽झ Ѿҗ۽ ݽ؛ਸ ߈ജפ findAll ݽف ח Ѫ۽
ݽ؛ ߓৌਸ ߈ജפ
const user = await User.findOne({});
console.log(user.nick); // 사용자 닉네임
6TFS ݽ؛ ࠁীب ߄۽ Ӕೡ ࣻ ݅ ؊ ಞܻೠ ҙ҅ ௪ܻܳ ਗೠח Ѫੑפ .Z42-۽ ٮ
ݶ +0*/ ӝמੑפ അ 6TFS ݽ؛ $PNNFOU ݽ؛җ hasMany-belongsTo ҙ҅о ݛযઉ णפ ݅ড
ౠ ࢎਊܳ оઉয়ݶࢲ Ӓ ࢎۈ ؆Ӗө ݽف оઉয়Ҋ रݶ include ࣘࢿਸ ࢎਊפ
const user = await User.findOne({
include: [{
model: Comment,
}]
});
console.log(user.Comments); // 사용자 댓글
যڃ ݽ؛җ ҙ҅о חܳ include ߓৌী ֍যݶ ؾפ ߓৌੋ ਬח নೠ ݽ؛җ ҙ҅о ਸ ࣻ
ӝ ٸޙੑפ ؆Ӗ ৈ۞ ѐੌ ࣻ ਵ۽ hasMany user.Comments۽ Ӕ оמפ ژח җ э
؆Ӗী Ӕೡ ࣻب णפ
const user = await User.findOne({});
const comments = await user.getComments();
console.log(comments); // 사용자 댓글
ҙ҅ܳ ࢸ೮ݶ getComments ઑഥ ৻ীب setComments ࣻ addComment ೞա ࢤࢿ addComments ৈ۞
ѐ ࢤࢿ removeComments ઁ ݫࢲ٘ܳ ਗפ زࢎ ٍী ݽ؛ ܴ ࠢח ഋधੑפ
زࢎ ٍ ݽ؛ ܴਸ ߄ԲҊ रݶ ҙ҅ ࢸ द as ২࣌ਸ ࢎਊೡ ࣻ णפ