-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Inconsistent Response Format for Custom Links When Single Item Is Present #10474
Comments
@maselious how are you querying it? I agree that this isn't expected |
@sradevski Middlewares export default defineMiddlewares({
routes: [
{
method: ['POST'],
matcher: '/admin/products/sync',
middlewares: [validateAndTransformBody(syncProductsSchema)]
},
{
method: ['POST'],
matcher: '/store/carts/:id',
additionalDataValidator: {
preferences: cartAddDataPreferencesSchema
}
}
]
}) GET /admin/products fields=variants.variant_image.url {
"products": [
{
"id": "prod_01JEE2CNFZ4WZ3NBPPS26FX56D",
"variants": [
{
"id": "variant_01JEE2CNH4VNS3XXPYMY0WD3N0",
"variant_image": {
"url": "...0007-01JEE2D42FZ4H3KJD9R49Z2AWH.png",
"id": "vimg_01JEE2D629MCE9611ZVA03RNES"
}
},
{
"id": "variant_01JEE2CNH3TWHN5EBFXS4F3JPG",
"variant_image": [
{
"url": "...XRTHD1DR6AV5Z8WJ.png",
"id": "vimg_01JEE2D9JMBEQCG4YFVX8DDFWS"
},
{
"url": "...27BNNCB97.png",
"id": "vimg_01JEE2D9JNPVA9WJ19MPPHABGZ"
},
{
"url": "...8N8PWHNVY.png",
"id": "vimg_01JEE2D9JNR44YPXKA3C11SM1Z"
}
]
},
{
"id": "variant_01JEE2CNH38N58A81H1SS99V8X",
"variant_image": [
{
"url": "...9YFC5PQ8P.png",
"id": "vimg_01JEE2D95WE9428WRMK8T3JC57"
},
{
"url": "...JDSVV27HT.png",
"id": "vimg_01JEE2D95XQ8848AHN0QDCJFJY"
},
{
"url": "...48PFG9BZQ.png",
"id": "vimg_01JEE2D95X20EBNKPVAMSVN41M"
}
]
},
{
"id": "variant_01JEE2CNH36QXEDCWDHJHD46W6",
"variant_image": [
{
"url": "...K7DM59YF51.png",
"id": "vimg_01JEE2D2M7WPAK43Y4CWSTA1HM"
},
{
"url": "...7FZT65GVB154KBFNV.png",
"id": "vimg_01JEE2D2M74S19DAXS6BS2576B"
}
]
},
{
"id": "variant_01JEE2CNH32NWXKYDVR26TFSK7",
"variant_image": [
{
"url": "...Q0895WXTSV22YZY.png",
"id": "vimg_01JEE2D3R0W99WW4BDF9RYHG61"
},
{
"url": "...CNYM489NA9ES7879D.png",
"id": "vimg_01JEE2D3R04KNYWGWEVWVHXEA2"
}
]
},
{
"id": "variant_01JEE2CNH4BXSREW72F9QD6SX0",
"variant_image": [
{
"url": "...W4XCJYG4D2M3GK463.png",
"id": "vimg_01JEE2D63FA0DDKV60S42GCZ36"
},
{
"url": "...M588MXZAKZ2P97Y.png",
"id": "vimg_01JEE2D63FFAGXMX8PJCFZXVQA"
}
]
},
{
"id": "variant_01JEE2CNH33KCHZQCGVF5466S6",
"variant_image": [
{
"url": "...Q3FW75YHCF5D8Y.png",
"id": "vimg_01JEE2D9PQ0JX2D497RDXB6XDG"
},
{
"url": "...EM9MW9NR13Z120.png",
"id": "vimg_01JEE2D9PRFWAVAZ0Q9JSHNDEF"
},
{
"url": "...6YMEPP66JC835.png",
"id": "vimg_01JEE2D9PR7J9G8KPCV526K7WM"
}
]
}
]
},
{
"id": "prod_01JEE2CNFZK79V4FN9MZBC36G0",
"variants": [
{
"id": "variant_01JEE2CNH3B0G1PB9BJ6JTQM8Q",
"variant_image": [
{
"url": "...CEN5M4XZ429EW.png",
"id": "vimg_01JEE2DA2C8W8GENWJD47BVS4K"
},
{
"url": "...ZEXQ789JP07GQB.png",
"id": "vimg_01JEE2DA2C8AQX7YFM0TDFVW5B"
},
{
"url": "...RC5NKBKAFMTMN.png",
"id": "vimg_01JEE2DA2CNDG7FZ172XHC2NSX"
}
]
},
{
"id": "variant_01JEE2CNH30Y3H5FN5X49VQ2JV",
"variant_image": [
{
"url": "...YDT0570N4NC3MR5.png",
"id": "vimg_01JEE2D9YNTC5HSD0Y8H5JFJER"
},
{
"url": "...CB45HMMM88BW.png",
"id": "vimg_01JEE2D9YPDHMJJW62DS95QMH8"
},
{
"url": "...2AAVZ72S5W9V.png",
"id": "vimg_01JEE2D9YP5AQSWJBYB1V3CKQD"
}
]
},
{
"id": "variant_01JEE2CNH3T7VMQ43JBJ4X4XYM",
"variant_image": [
{
"url": "...SC5388SVY9BFD.png",
"id": "vimg_01JEE2D62CSFG99FG86JH01HF9"
},
{
"url": "...AQ633DCF4DAPT0.png",
"id": "vimg_01JEE2D62CCB5SB30YSWTVJK2R"
},
{
"url": "...5VYSPVSG9AQ.png",
"id": "vimg_01JEE2D62DGS6T881QZQK3G58P"
}
]
},
{
"id": "variant_01JEE2CNH316Y8ZVH0MW68BPTN",
"variant_image": [
{
"url": "...X6TA46RPEM0EAPR.png",
"id": "vimg_01JEE2D8BB8N3JNNCBJZFF3K8P"
},
{
"url": "...M419PTZSXV2HZE3.png",
"id": "vimg_01JEE2D8BB49YSEPYHCR79N875"
},
{
"url": "...BHHKV07J9A6W014.png",
"id": "vimg_01JEE2D8BBHP5QGKXTP78NSEXR"
}
]
},
{
"id": "variant_01JEE2CNH371BJ1JVC0A4J87PQ",
"variant_image": [
{
"url": "...TH7DDC9KTYHG347TG.png",
"id": "vimg_01JEE2DA563P8G3YY8VZD7KVZK"
},
{
"url": "...1EV8CD29VEFAHB2.png",
"id": "vimg_01JEE2DA5609EMQZ2NWTG8KQ1V"
},
{
"url": "...2ET66K89P6AYAGZ8.png",
"id": "vimg_01JEE2DA56JN49EWXC0221VTFJ"
}
]
}
]
}
],
"count": 2,
"offset": 0,
"limit": 2
} |
Ok thanks, we'll have a look at it! |
Hi @maselious, export default defineLink(
ProductModule.linkable.productVariant,
{
...VariantImages.linkable.variantImage.id,
isList: true,
},
{
database: {
table: 'variant_image_links',
}
}
); |
Perfect, thank you! Then there is another issue i would say: if the link is one-to-one, there should be an error while trying to assign an array or the relations should be overridden, isnt it? I made it as written in the doc export default defineLink(
ProductModule.linkable.productVariant,
{
linkable: VariantImages.linkable.variantImage,
isList: true
},
{
database: {
table: 'variant_image_links'
}
}
) |
Package.json file
Node.js version
v20.9.0
Database and its version
Postgre SQL 17
Operating system name and version
Mac Os 15.1.1 (24B91)
Browser name
Arc
What happended?
When creating a custom link using defineLink, if there is only one linked item (e.g., a single image), the response returns an object instead of an array. However, when there are multiple items, the response correctly returns an array. This inconsistency complicates data handling on the client side.
Link Defination
Expected behavior
The response should consistently return an array, even when there is only one linked item, to ensure uniform data handling.
Actual behavior
For a single linked image, the response is an object:
For multiple linked images, the response is an array:
Link to reproduction repo
private repo
The text was updated successfully, but these errors were encountered: