Belongs To Many query not including through attributes
alirizwan opened this issue · 3 comments
Hi, I have two models with belongsToMany relations and through table has one extra data column. When I use dataloader the query skips through columns and generates something like this:
SELECT `Attribute`.`id`, `Attribute`.`name`, `Attribute`.`createdAt`, `Attribute`.`updatedAt`, `ProductAttributes`.`attributeId` AS `ProductAttributes.attributeId`, `ProductAttributes`.`productId` AS `ProductAttributes.productId` FROM `Attributes` AS `Attribute` INNER JOIN `ProductAttributes` AS `ProductAttributes` ON `Attribute`.`id` = `ProductAttributes`.`attributeId` AND `ProductAttributes`.`productId` IN (1, 2);
When I stop using dataloader the query generates something like this:
SELECT `Attribute`.`id`, `Attribute`.`name`, `Attribute`.`createdAt`, `Attribute`.`updatedAt`, `ProductAttribute`.`value` AS `ProductAttribute.value`, `ProductAttribute`.`createdAt` AS `ProductAttribute.createdAt`, `ProductAttribute`.`updatedAt` AS `ProductAttribute.updatedAt`, `ProductAttribute`.`attributeId` AS `ProductAttribute.attributeId`, `ProductAttribute`.`productId` AS `ProductAttribute.productId` FROM `Attributes` AS `Attribute` INNER JOIN `ProductAttributes` AS `ProductAttribute` ON `Attribute`.`id` = `ProductAttribute`.`attributeId` AND (`ProductAttribute`.`productId` = 1);
There's no batching but it has included all the attributes from through table, see ProductAttribute
.value
AS ProductAttribute.value
.
I am struggling to figure this out how can I leverage dataloader and still get all through columns, I have tried passing attributes in through parameter as well.
I looked at the code and figured
dataloader-sequelize/src/index.js
Line 129 in 4cf6926
is the culprit. If I comment that line out it works fine for obvious reasons. Is it intentional or should it be considered a bug and a PR should be raised on this? @mickhansen
@alirizwan I don't recall there being any intention other than limiting attributes (to save a little memory) so can be considered a bug, PR definitely welcome (with a test please)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.