-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
bugSomething isn't workingSomething isn't working
Description
I am experiencing an issue with the nestjs-query library concerning the relationship between Goods and GoodsOption entities. Despite the correct execution of the following SQL query, some values are not being returned in the final response:
SELECT
`Goods`.`goods_id` AS `Goods_goods_id`,
`Goods`.`mall` AS `Goods_mall`,
`goods_option`.`goods_id` AS `Goods_goods_option_GoodsId`,
`goods_option`.`name` AS `Goods_goods_option_name`
FROM `commerce`.`goods` `Goods`
INNER JOIN `commerce`.`goods_option` `goods_option`
ON `goods_option`.`goods_id` = `Goods`.`goods_id`
WHERE `goods_option`.`goods_id` IN ('12345678901', '12345678902', '12345678903', '12345678904', '12345678905', '12345678906', '12345678907', '12345678908', '12345678909', '12345678910')
AND `goods_option`.`name` IN ('Item A', 'Item B', 'Item C', 'Item D', 'Item E', 'Item F', 'Item G', 'Item H', 'Item I', 'Item J')
ORDER BY `Goods`.`goods_id` DESC
LIMIT 10;
The entities and DTOs are defined as follows:
@Entity('goods_option')
export class GoodsOptionEntity {
@Column('varchar', {
name: 'goods_id',
length: 64,
primary: true,
unique: true
})
goodsId: string;
@Column('varchar', {
name: 'name',
length: 250,
primary: true,
unique: true
})
name: string;
@ManyToOne(() => GoodsEntity, goods => goods.goodsOptions, {
createForeignKeyConstraints: false
})
@JoinColumn([{ name: 'goods_id', referencedColumnName: 'goodsId' }])
goods?: GoodsEntity;
}
@ObjectType('GoodsOption')
@Relation('goods', () => GoodsDTO, {
nullable: true
})
export class GoodsOptionDTO {
@Field()
goodsId: string;
@FilterableField()
name: string;
}
@Entity('goods')
export class GoodsEntity {
@PrimaryColumn('varchar', {
name: 'goods_id',
length: 64,
primary: true
})
goodsId: string;
@OneToMany(() => GoodsOptionEntity, goodsOption => goodsOption.goods, {
createForeignKeyConstraints: false
})
goodsOptions?: GoodsOptionEntity[];
}
@ObjectType('Goods')
export class GoodsDTO {
@FilterableField()
goodsId: string;
}
It appears that the goods relation is not being properly resolved, leading to incomplete data in the response. Could you please provide guidance on how to address this issue?
The issue is not that goodsOption.goods is entirely missing from the response. If 10 results are returned, some of them are partially missing data. In the SQL results, all goods entries are correctly retrieved, but some goodsOption.goods values are returned as null.
ParasPandeyE
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working