Ich testete das folgende Employee.js-Modell in Sails.js und ich fand etwas, das schwer für mich zu verstehen scheint.Modellvalidierung fehlgeschlagen in Sails.js
Wenn das Formular zum Erstellen eines neuen Mitarbeiters gebucht wird, habe ich die folgenden Fehler mit der ersten Definition von Employee.js Modell, aber die zweite Definition von Employee.js funktioniert. Was ist der Unterschied zwischen den beiden Definitionen von Employee.js?
Fehler:
Error (E_VALIDATION) :: 3 attributes are invalid
at WLValidationError.WLError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:33:18)
at new WLValidationError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLValidationError.js:20:28)
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/validate.js:45:43
at allValidationsChecked (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:195:5)
at done (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:135:19)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:32:16
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:186:14
at done (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:135:19)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:32:16
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:157:64
Invalid attributes sent to Employee:
• name
• `undefined` should be a string (instead of "null", which is a object)
• "required" validation rule failed for input: null
• email
• `undefined` should be a email (instead of "null", which is a object)
• "required" validation rule failed for input: null
• password
• `undefined` should be a string (instead of "null", which is a object)
• "required" validation rule failed for input: null
Definition 1: Employee.js
module.exports = {
attributes: {
name: {
type: 'STRING',
},
email: {
type: 'STRING',
email: true,
},
password: {
type: 'STRING',
},
toJSON: function() {
var obj = this.toObject();
return {
name: obj.name,
email: obj.email,
password: obj.password
}
}
}
};
Definition2: Employee.js
module.exports = {
attributes: {
name: 'STRING',
email: 'STRING',
password: 'STRING',
toJSON: function() {
var obj = this.toObject();
return {
name: obj.name,
email: obj.email,
password: obj.password
}
}
}
};
Die Form für einen neuen Mitarbeiter schaffen, ist wie folgt:
<form action="/signupemployee" method="POST">
<table>
<tr><td>Name</td><td><input type=”text” name=”name”></td></tr>
<tr><td>Password</td><td><input type=”password” name=”password”></td></tr>
<tr><td>Email</td><td><input type=”email” name=”email”></td></tr>
<tr><td></td><td><input type="submit"></td>
</table>
</form>
Was wie die Route und Controller aussehen tut? – CaseyWebb