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

virtual attributes are not serialized to JSON when returned in koa middleware #1270

Closed
capaj opened this issue Apr 1, 2019 · 6 comments
Closed

Comments

@capaj
Copy link
Contributor

capaj commented Apr 1, 2019

we had this working correctly in 1.6.3, but after upgrading to 1.6.6 we lost all virtual attributes in the JSON we get back from the API

@koskimas
Copy link
Collaborator

koskimas commented Apr 1, 2019

Let's try this again, this time with some information. There are tests for virtual attributes. They all pass.

@capaj
Copy link
Contributor Author

capaj commented Apr 1, 2019

I have this model:
image
and calling toJSON produces same result in both 1.6.3 and 1.6.6:
image
logs:
image

but when I return this in koa middleware, the virtual attributes are not included-this is the payload I get for 1.6.3
image

this is the payload I get for 1.6.6
image

no other dependency has changed in my stack.

@koskimas
Copy link
Collaborator

koskimas commented Apr 1, 2019

If toJSON() works as expected, how could this be objection's fault? Unless koa somehow passes an object with { virtuals: [] } or { virtuals: false } to toJSON. I'm afraid I'll need a reproduction for this. There's a test case for nested virtuals too and it works.

@koskimas
Copy link
Collaborator

koskimas commented Apr 1, 2019

If not a reproduction, at least I'll need something more to work with so that I can reproduce this.

@capaj
Copy link
Contributor Author

capaj commented Apr 1, 2019

I'll close this for now and reopen only if I can add a unit test.

@capaj capaj closed this as completed Apr 1, 2019
@capaj capaj changed the title virtual attributes are not serialized to JSON virtual attributes are not serialized to JSON when returned in koa middleware Apr 1, 2019
@koskimas koskimas reopened this Apr 2, 2019
@koskimas
Copy link
Collaborator

koskimas commented Apr 2, 2019

Found the bug. Sorry about this. I'm releasing 1.6.7 right now.

capaj pushed a commit to capaj/objection.js that referenced this issue Apr 2, 2019
…ithout virtuals property. fixes Vincit#1270

# Conflicts:
#	package.json
flipace pushed a commit to flipace/objection.js that referenced this issue May 7, 2019
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