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

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 9, 2015

Owner

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?

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

This comment has been minimized.

Show comment
Hide comment
@jede

jede Apr 10, 2015

Sounds amazing! 👍

jede commented Apr 10, 2015

Sounds amazing! 👍

@ansman ansman closed this in 525db94 Apr 11, 2015

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 11, 2015

Owner

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

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

This comment has been minimized.

Show comment
Hide comment
@jede

jede Apr 13, 2015

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

jede commented Apr 13, 2015

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

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 13, 2015

Owner

@jede It passed the attributed before as well

Owner

ansman commented Apr 13, 2015

@jede It passed the attributed before as well

@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Jul 3, 2015

Owner

Released in 0.8.0 (42e5cb3)

Owner

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