'How to use take() options with relations?
I don't know why take() options not get correct number as I expect.
Example ,I type take:2 but it just get one product, but when I remove relations it work normal.It is so strange with me,Am I missing something?
My code
async getProducts(@Arg("searchOptions") searchOptions : SearchOptionsInput): Promise<ProductResponse> {
try {
const {skip,type} = searchOptions
const findOptions: { [key: string]: any } = {
skip,
take: 2,
relations: ["prices"],
};
switch (type) {
case "PRICE_DESC":
findOptions.order = {
prices: {
price: "DESC"
}
}
break;
default:
findOptions.order = {
createdAt:"DESC"
}
break;
}
const products = await Product.find(findOptions);
return {
code: 200,
success: true,
products,
};
} catch (error) {
return {
code: 500,
success: false,
message: `Server error:${error.message}`,
};
}
}
My query
query GetProducts{
getProducts(searchOptions:{
skip:0,
type:"PRICE_DESC"
}){
code
success
products{
id
prices{
price
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
