Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Docs mistake with beforeValidate #243

Open
OscarGodson opened this issue Dec 14, 2014 · 1 comment
Open

Docs mistake with beforeValidate #243

OscarGodson opened this issue Dec 14, 2014 · 1 comment
Labels

Comments

@OscarGodson
Copy link
Member

I'm pretty sure this code in the docs doesn't work (its under https://github.com/geddy/model#lifecycle-events):

  this.beforeValidate = function (params) {
    params.name = params.name || 'Zerp Derp';
  };

Note that it's not returning anything nor does it set any params on any object like this.params. I didn't see any specs that actually check for this, but I could be missing it.

When I try that in my code my default params arent updated. If I have this code:

  this.beforeValidate = function (params) {
    params.permission_level = params.permission_level || 1;
  };

  this.defineProperties({
    permission_level: { type: 'number', required: true }
  });

I still get an error:

{ permission_level: '[[model.validatesPresent]]' }

For now I can use afterCreate and set it as required: false (since I'll be forcing a value if null). I can update the docs if the above is indeed incorrect. I couldn't figure out the right syntax tho.

@mde
Copy link
Contributor

mde commented Dec 14, 2014

Weird, it looks like beforeValidate is getting called in the right place in the lifecycle:

https://github.com/geddy/model/blob/master/lib/index.js#L730

This is at the top, before it begins calling validateProperty on each prop. It should be working right.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants