Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

sails checks for required before the beforeCreate method on creation #109

Open
hassench opened this issue Aug 19, 2019 · 0 comments
Open

Comments

@hassench
Copy link

Hi,

I can't find the logic of verifying if a field is undefined when it's marked as required, before the beforeCreate!
Example:
reference: {type: 'string', columnType: 'string', columnName: "reference", required: true},
then

self.beforeCreate = function (values, next) {
  values.reference = sails.helpers.generateRandomString();
  next();
};

Here I'm generating the reference in beforeCreate, which is logical. I should create a reference only here, it's simply a unique random string. So I'm sure that it will always be there.

But I have an error saying the reference is undefined while it's required, when I'm trying to create a new record of my model.

Of course when I remove required: true everything is fine, but that's not what I want.

The logical sequence is to check for undefined and do all the validations AFTER the beforeCreate function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant