You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const Event = sequelize.define('event', {
// fields defined
});
const Question = sequelize.define('question', {
description: {
type: Sequelize.STRING,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Description should be set.' }
},
},
// other fields defined
});
Event.hasMany(Question);
Question.belongsTo(Event);
Then I'm creating an Event instance with Question instance this way:
const body = {
questions: [
{ description: '' } // is obviously invalid
],
// some other fields
}
const newEvent = await Event.create(body, {
include: [ Question ]
});
What is happening?
I am getting SequelizeValidationError (which is what's expected) with one ValidationErrorItem (also expected), but the path value of it is absolute ('description'):
{
"message": "Description should be set.",
"type": "Validation error",
"path": "description",
"value": "",
"origin": "FUNCTION",
"instance": {
"required": true,
"id": null,
"description": "",
"event_id": 60,
"updated_at": "2018-06-11T12:25:04.666Z",
"created_at": "2018-06-11T12:25:04.666Z"
},
"validatorKey": "notEmpty",
"validatorName": "notEmpty",
"validatorArgs": [
{
"msg": "Description should be set."
}
],
"__raw": {
"validatorName": "notEmpty",
"validatorArgs": [
{
"msg": "Description should be set."
}
]
}
}
What do you expect to happen?
It would be awesome to get the relative path value, like in Mongoose (if I'd do simular scheme in Mongoose, the path value would be something like questions.0.description. That way it would be more clear which child is invalid (especially with multiple children, or if your parent model has fields which have the same name as the children model).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
This feature will make it possible to return errors with enough information to present in the front end on the corresponding input fields. Without it, it's quite difficult.
What are you doing?
I have this schema structure:
Then I'm creating an Event instance with Question instance this way:
What is happening?
I am getting
SequelizeValidationError
(which is what's expected) with oneValidationErrorItem
(also expected), but thepath
value of it is absolute ('description'):What do you expect to happen?
It would be awesome to get the relative
path
value, like in Mongoose (if I'd do simular scheme in Mongoose, thepath
value would be something likequestions.0.description
. That way it would be more clear which child is invalid (especially with multiple children, or if your parent model has fields which have the same name as the children model).Dialect: postgres
Dialect version:
Database version: PostgreSQL 9.6
Sequelize version:
Tested with latest release: No
The text was updated successfully, but these errors were encountered: