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

how to limit attributes on resource? #99

Closed
philotas opened this issue Oct 8, 2015 · 5 comments
Closed

how to limit attributes on resource? #99

philotas opened this issue Oct 8, 2015 · 5 comments

Comments

@philotas
Copy link

philotas commented Oct 8, 2015

when I do a list or read, how do I limit the attributes to the one I want?

I don't want to send the password of a user to begin with.

I know I can specify the attributes when I include another resource, but what about the plain resource when read/list itself?

I am sure it has to be possible but I don't seem to be seeing it.

Or do I have to use a hook/milestone and delete the fields before sending? This seems to be the wrong approach.

thanks for your help!

@mbroadst
Copy link
Collaborator

mbroadst commented Oct 8, 2015

We don't currently support explicitly including/excluding certain attributes during resource definition, but it's not a bad idea. If you don't want to do any work on the module itself the way to go today is to remove the attributes you don't want to expose with a milestone.

If, on the other hand, you're interested in helping build out the feature: we already work with options.attributes here in order to remove duplicate returned data when using includes. You could perhaps provide a top level attributes and/or excludeAttributes option to epilogue.resource which could further fine-tune that parameter before sending it to model.find below. This would be a pretty quick fix if you were so inclined

@philotas
Copy link
Author

philotas commented Oct 8, 2015

Ok. I am quite new to node, express and sequelize etc, but I gave it a shot:

philotas@5667765

It now works as I wished and currently it only supports attributes but not excludeAttributes.

I also did no write any test but the existing tests ran without errors.

If you have any suggestions for improvements, feel free to let me know. Thanks!

@mbroadst
Copy link
Collaborator

@philotas thanks for the work! I'll pull it in presently and write a test or two for it. Are you sure that excludeAttributes wouldn't suite your purposes better? That way you wouldn't have to manually write out each attribute, just the ones you don't want

@mbroadst
Copy link
Collaborator

@philotas merged in e30fbfd, you were attributed in the previous commit. I went with excludeAttributes as that seems to be the primary use case, however resource.attributes still exists and can be modified directly

@philotas
Copy link
Author

thanks!

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

No branches or pull requests

2 participants