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

Unintended object in attributes #122

Closed
shankiflang opened this issue Apr 29, 2021 · 2 comments
Closed

Unintended object in attributes #122

shankiflang opened this issue Apr 29, 2021 · 2 comments

Comments

@shankiflang
Copy link

Hello,

I currently have this code in my serializer :
export default { jsonapiObject: false, id: 'id', links: { self: function (data) { return '/v1/ingredients/' + data.id }, }, }
that returns lots of data in attrtibutes like in code bellow. Is there any way to return only the basic attributes?
{ "data": [ { "type": "ingredients", "id": "6082d2ff72de5a0cb0e08a42", "attributes": { "$__": {} "isNew": false, "$locals": {}, "$op": null, "_doc": { "_id": "6082d2ff72de5a0cb0e08a42", "name": "XXX", "category": "XXX" }, "$init": true }, "links": { "self": "/v1/ingredients/6082d2ff72de5a0cb0e08a42" } } ] }

@danivek
Copy link
Owner

danivek commented May 3, 2021

@shankiflang I think you are working with an ORM object (seems to be a mongoose Document in your exemple).

It will work better if you call .toJSON() or .toObject() before passing it to the serializer.

@shankiflang
Copy link
Author

@danivek I just added a .lean() at the end of my .find() and it seems to have fixed the problem. Thanks for your help.

@danivek danivek closed this as completed May 3, 2021
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