Node version: 8.16.0
Sails version _(sails)_: 1.2.1
ORM hook version _(sails-hook-orm)_: 2.1.1
DB adapter & version _(sails-mysql)_: 1.0.1
When creating a record in the database, following code executes
Model.create(initialValues);
Let's say that initialValues object has some additional attributes that Model don't have.
initialValues object is normalized (additional attributes are omitted) before lifecycle callback beforeCreate is called.
In sails v0.12 initialValues object was normalized after beforeCreate lifecycle callback, but in versions after 1.0 this has changed. Why? Now I have problems upgrading my application.
If I set schema: false in config/models.js initialValues object is not normalized. But then I have to omit additional attributes by myself otherwise, the error ER_BAD_FIELD_ERROR happens.
If I want to do this (omit additional attributes) in beforeCreate in config/models.js I can't. because I don't know which specific model is being created, so I don't know which attributes to omit.
Help is needed
@Alessy Thanks for posting! We'll take a look as soon as possible.
In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.
For help with questions about Sails, click here.
Hi Alessy,
We have facing same issue while upgrading sails 0.12 to 1.0
You need to add extra settings:
module.exports.models.attributes.id = { type: 'string', autoIncrement: true }
and
beforeCreate: function (modelObj, next) {
modelObj.id = uuidv4(); // generate unique id
next();
}
and remove id field from model attribute.
Thanks
@RavirajKakadeGit Thanks for that! @Alessy Were you able to use this workaround?
You might also have greater success (and flexibility) with handling data formatting in your action instead. 馃憤
This workaround doesn't help me. I handle data in action now. Thanks
@Alessy So besides the workaround, going with an action has helped instead?
@johnabrams7 Yes, it helped
Most helpful comment
Hi Alessy,
We have facing same issue while upgrading sails 0.12 to 1.0
You need to add extra settings:
module.exports.models.attributes.id = { type: 'string', autoIncrement: true }andand remove id field from model attribute.
Thanks