Objection.js: queryBuilder.toString() not working correctly

Created on 4 May 2020  路  5Comments  路  Source: Vincit/objection.js

I'm not sure when this stopped working, but I'm using Objection v2.1.3 and when I call MyModel.query().toString() I get [object QueryBuilder] (same with .toSql()). Previously I would get a string of SQL. This is in an older part of my codebase that was written early last year sometime. Has the usage of toString/toSql changed since then? I'm looking at the documentation on the site and I don't see where I could be going wrong here. Any help would be very much appreciated. Thanks!

Most helpful comment

Oh damn! I'll fix those asap. I had no idea those were outdated. Thanks for pointing this out.

All 5 comments

It was removed in 2.0. See the list of breaking changes. You can use toKnexQuery().toSQL()

Thanks @koskimas. It would be cool if that was noted in the documentation :thumbsup:

It is.

https://vincit.github.io/objection.js/release-notes/migration.html#querybuilder-tostring-and-querybuilder-tosql-have-been-removed

Yeah, I found that after your comment yesterday, but I'm talking about these:
https://vincit.github.io/objection.js/api/query-builder/other-methods.html#tostring
https://vincit.github.io/objection.js/api/query-builder/other-methods.html#tosql

Those are what I was looking at originally and was very confused as to why it wasn't working. It would be very helpful if there was a note there, and especially if that includes the migration link you just referenced.

Oh damn! I'll fix those asap. I had no idea those were outdated. Thanks for pointing this out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chen7david picture chen7david  路  3Comments

nazar picture nazar  路  3Comments

mycahjay-nms picture mycahjay-nms  路  4Comments

rickmed picture rickmed  路  4Comments

nicolaracco picture nicolaracco  路  3Comments