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 ২࣌ਸ ࢎਊೡ ࣻ ੓णפ׮
   310   311   312   313   314   315   316   317   318   319   320