-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Description
Describe the bug
I am using lifecycle hooks in models to update fields and create the content for my own slug fields. This works, if the draft-System is off. But when I activate the draft system, data.fieldname is undefined.
Steps to reproduce the behavior
- Turn off the draft-system for a collection
- Change data and save them
- The lifecacle hooks beforeUpdate and beforeCreate are working as expected
- Turn on the draft-system for the collection
- unpublish or edtit fields
- The field are not changed correctly by lifecycle hook, but getting undefined.
Code snippets
/api/product/models/product.js
'use strict';
const slugify = require('slugify');
const mySlugify = (slug) => {
return (
slugify(slug, {
remove:/[*+~.(){}\[\]\\/'"!:@,]/g,
lower:true
})
);
};
/**
* Lifecycle callbacks for the `product` model.
*/
module.exports = {
lifecycles: {
async beforeCreate(data) {
if (!data.name_en) {
data.name_en = data.name_de;
}
data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
},
async beforeUpdate (params,data) {
console.log(data);
if (!data.name_en) {
data.name_en = data.name_de;
}
data.slug_de = mySlugify(data.name_de + '-' + data.orderno);
data.slug_en = mySlugify(data.name_en + '-' + data.orderno);
}
}
};
In another collection doing the same, data.name_de is logged as undefined, but there is a string in that field.
System
- Node.js version: v12.18.4
- NPM version: 6.14.6
- Strapi version: 3.2.3
- Database: sqlite
- Operating system: Windows 10 Pro

