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 ஸۢਸ оܻఃҊ ੓ण

         פ׮
   303   304   305   306   307   308   309   310   311   312   313