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

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
Milestone

Comments

@jede
Copy link

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
Copy link
Owner

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 commented Apr 10, 2015

Sounds amazing! 👍

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

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 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 commented Apr 13, 2015

@jede It passed the attributed before as well

@ansman
Copy link
Owner

ansman commented Jul 3, 2015

Released in 0.8.0 (42e5cb3)

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

No branches or pull requests

2 participants