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

Call toJson in representer logic #7

Open
driescroons opened this issue Mar 16, 2022 · 3 comments
Open

Call toJson in representer logic #7

driescroons opened this issue Mar 16, 2022 · 3 comments

Comments

@driescroons
Copy link

In listRepresenter, we call the toJson method. Why don't we do this for Representer?

Argument could be made here that for creation routes, these entities don't have a toJson method, however, this can be simple fixed by returnijng a wrapped entity.

from

return getById(id);

to

return wrap(await getById(id));

This comes in especially handy when you have a parent - children entity, that upon initialization has an empty collection. Without the wrap, and with em.create, it will return the parent with an object children, even though it's an array. Wrapping in every create and toJsoning in the representer fixes this.

@ljobse
Copy link
Member

ljobse commented Mar 17, 2022

Representer should be completely independent from any orm so the fact it's there in the listRepresenter seems incorrect to me

@driescroons
Copy link
Author

than we need to add another useInterceptor before our representer that calls this for our orm objects. It's required for orm entities to be serialized. For example; when you have an nested collection, without toJson it'll return an object if it's empty.

@ljobse
Copy link
Member

ljobse commented Mar 18, 2022

Yep indeed, but we can find a more elegant way to incorporate it

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