From f504632fe68618180a89505e0db6ba5147ef1ca2 Mon Sep 17 00:00:00 2001 From: sooxt98 Date: Sun, 28 May 2023 11:57:26 +0800 Subject: [PATCH] Update polymorphic-associations.md the comment should be two way scoping to prevent excess eagerLoading when using Comment.findAll, with this it only include the specific commentableType --- .../advanced-association-concepts/polymorphic-associations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/versioned_docs/version-6.x.x/advanced-association-concepts/polymorphic-associations.md b/versioned_docs/version-6.x.x/advanced-association-concepts/polymorphic-associations.md index da2c6d79..969a77d3 100644 --- a/versioned_docs/version-6.x.x/advanced-association-concepts/polymorphic-associations.md +++ b/versioned_docs/version-6.x.x/advanced-association-concepts/polymorphic-associations.md @@ -98,7 +98,7 @@ Image.hasMany(Comment, { commentableType: 'image' } }); -Comment.belongsTo(Image, { foreignKey: 'commentableId', constraints: false }); +Comment.belongsTo(Image, { foreignKey: 'commentableId', constraints: false, scope: { '$comment.commentableType$': 'image' } }); Video.hasMany(Comment, { foreignKey: 'commentableId', @@ -107,7 +107,7 @@ Video.hasMany(Comment, { commentableType: 'video' } }); -Comment.belongsTo(Video, { foreignKey: 'commentableId', constraints: false }); +Comment.belongsTo(Video, { foreignKey: 'commentableId', constraints: false, scope: { '$comment.commentableType$': 'video' } }); Comment.addHook("afterFind", findResult => { if (!Array.isArray(findResult)) findResult = [findResult];