Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Clean validated data #43

Closed
jede opened this issue Apr 9, 2015 · 6 comments
Closed

Clean validated data #43

jede opened this issue Apr 9, 2015 · 6 comments
Labels
Milestone

Comments

@jede
Copy link

@jede jede commented Apr 9, 2015

It would be great to use validate to clean the data a user sends in. Basically I want a way to whitelist attributes to make them optional. So for a user you should be able to pass in description, but not createdAt. Here is a example of how it could work:

data = 
  name: 'Test'
  description: 'Yaay'
  createdAt: 'omgomg'

constraints =
  name:
    presence: true
  description: true

validate.async(data, constraints).then (params) =>
  # params won't contain createdAt
  User.create(params)
@ansman ansman added this to the Next milestone Apr 9, 2015
@ansman ansman added the enhancement label Apr 9, 2015
@ansman
Copy link
Owner

@ansman ansman commented Apr 9, 2015

Great idea.

My proposal is the following:

  • validate.async passes the attributes to the resolve callback.
  • validate.async cleans the data unless a new cleanAttributes is set to false
  • validate.cleanAttributes will be added that accepts an object with the attributes to keep (will also accept constraints)

Sounds resonable?

@jede
Copy link
Author

@jede jede commented Apr 10, 2015

Sounds amazing! 👍

@ansman ansman closed this in 525db94 Apr 11, 2015
@ansman
Copy link
Owner

@ansman ansman commented Apr 11, 2015

There we go, though I'm not sure I think clean attributes should be on per default since it can break backward compatibility, what do you think @jede

@jede
Copy link
Author

@jede jede commented Apr 13, 2015

Not sure. If the output from async previously was not defined, then I think its ok!

@ansman
Copy link
Owner

@ansman ansman commented Apr 13, 2015

@jede It passed the attributed before as well

@ansman
Copy link
Owner

@ansman ansman commented Jul 3, 2015

Released in 0.8.0 (42e5cb3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.