Objection.js: virtual attributes are not serialized to JSON when returned in koa middleware

Created on 1 Apr 2019  路  6Comments  路  Source: Vincit/objection.js

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

All 6 comments

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

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.

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings