website icon indicating copy to clipboard operation
website copied to clipboard

Update polymorphic-associations.md

Open sooxt98 opened this issue 2 years ago • 3 comments

the comment should be two way scoping to prevent excess eagerLoading when using Comment.findAll, with this it only include the specific commentableType

sooxt98 avatar May 28 '23 03:05 sooxt98

That will only work when eager loading, but will break all lazy-loaders. I do not recommend doing this. I also don't see what this fixes. Could you provide a query that does not behave as expected?

ephys avatar May 28 '23 10:05 ephys

@ephys it added these 3 lines when using Rating.findAll , which prevent all three included rateableType to find together when id = xxx , because theres always all three rateableType result come out together for each rating, but it should be just one, which i think this will affect the performance

image

sooxt98 avatar May 28 '23 11:05 sooxt98

There is a warning about it in the new documentation: https://648dd325deb93b14ad86d83a--sequelize-site.netlify.app/docs/v7/associations/polymorphic-associations/#single-model-single-foreign-key-polymorphic-associations

But the proposed solution is unfortunately not something we can put in our documentation, as it will only lead to more issues

Right now the best we can do is copy that warning in the Sequelize 6 documentation

ephys avatar Jun 17 '23 15:06 ephys