System Information
- Strapi Version: v4.1.12
- Operating System: macos monterey 12.4
- Database: mariadb 10.6.4
- Node Version: v14.18.1
- NPM Version: 8.12.1
- Yarn Version: 1.22.17
Hello! I use this API for updating components inside order entity.
https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/entity-service/components-dynamic-zones.html#creation
This is my code
module.exports = {
async afterCreate(event) {
const { data } = event.params.data;
const order = await strapi
.query("api::order.order")
.findOne({ where: { id: data.id }, populate: ["history"] });
const result = await strapi.query("api::order.order").update({
where: { id: data.id },
data: {
status: data.status,
history: [
...order.history,
{
status: data.status,
date: new Date().getTime(),
},
],
},
});
},
};
I need to add a new history record in the order entity. But I got following error.
error: Invalid id, expected a string or integer, got [object Object]
This error throws here
const toAssocs = data => {
return _.castArray(data)
.filter(datum => !_.isNil(datum))
.map(datum => {
// if it is a string or an integer return an obj with id = to datum
if (isValidId(datum)) {
return { id: datum, __pivot: {} };
}
// if it is an object check it has at least a valid id
if (!_.has('id', datum) || !isValidId(datum.id)) {
throw new Error(`Invalid id, expected a string or integer, got ${datum}`);
}
return datum;
});
};
In strapi package
node_modules/@strapi/database/lib/entity-manager.js:25:15